Package org.bitcoinj.base.utils
Class Fiat
- java.lang.Object
-
- org.bitcoinj.base.utils.Fiat
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringcurrencyCodestatic intSMALLEST_UNIT_EXPONENTThe absolute value of exponent of the value of a "smallest unit" in scientific notation.longvalueThe number of smallest units of this monetary value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Fiatadd(Fiat value)intcompareTo(Fiat other)Fiatdivide(long divisor)longdivide(Fiat divisor)Fiat[]divideAndRemainder(long divisor)booleanequals(java.lang.Object o)java.lang.StringgetCurrencyCode()longgetValue()Returns the number of "smallest units" of this monetary value.inthashCode()booleanisGreaterThan(Fiat other)Returns true if the monetary value represented by this instance is greater than that of the given other Fiat, otherwise false.booleanisLessThan(Fiat other)Returns true if the monetary value represented by this instance is less than that of the given other Fiat, otherwise false.booleanisNegative()Returns true if and only if this instance represents a monetary value less than zero, otherwise false.booleanisPositive()Returns true if and only if this instance represents a monetary value greater than zero, otherwise false.booleanisZero()Returns true if and only if this instance represents zero monetary value, otherwise false.longlongValue()Returns the number of "smallest units" of this monetary value.Fiatmultiply(long factor)Fiatnegate()static FiatparseFiat(java.lang.String currencyCode, java.lang.String str)Parses an amount expressed in the way humans are used to.static FiatparseFiatInexact(java.lang.String currencyCode, java.lang.String str)Parses an amount expressed in the way humans are used to.intsignum()intsmallestUnitExponent()Returns the absolute value of exponent of the value of a "smallest unit" in scientific notation.Fiatsubtract(Fiat value)java.lang.StringtoFriendlyString()Returns the value as a 0.12 type string.java.lang.StringtoPlainString()Returns the value as a plain string.java.lang.StringtoString()static FiatvalueOf(java.lang.String currencyCode, long value)
-
-
-
Field Detail
-
SMALLEST_UNIT_EXPONENT
public static final int SMALLEST_UNIT_EXPONENT
The absolute value of exponent of the value of a "smallest unit" in scientific notation. We picked 4 rather than 2, because in financial applications it's common to use sub-cent precision.- See Also:
- Constant Field Values
-
value
public final long value
The number of smallest units of this monetary value.
-
currencyCode
public final java.lang.String currencyCode
-
-
Method Detail
-
valueOf
public static Fiat valueOf(java.lang.String currencyCode, long value)
-
smallestUnitExponent
public int smallestUnitExponent()
Description copied from interface:MonetaryReturns the absolute value of exponent of the value of a "smallest unit" in scientific notation. For Bitcoin, a satoshi is worth 1E-8 so this would be 8.- Specified by:
smallestUnitExponentin interfaceMonetary
-
getValue
public long getValue()
Returns the number of "smallest units" of this monetary value.
-
getCurrencyCode
public java.lang.String getCurrencyCode()
-
parseFiat
public static Fiat parseFiat(java.lang.String currencyCode, java.lang.String str)
Parses an amount expressed in the way humans are used to.
This takes string in a format understood by
BigDecimal(String), for example "0", "1", "0.10", "1.23E3", "1234.5E-5".- Throws:
java.lang.IllegalArgumentException- if you try to specify more than 4 digits after the comma, or a value out of range.
-
parseFiatInexact
public static Fiat parseFiatInexact(java.lang.String currencyCode, java.lang.String str)
Parses an amount expressed in the way humans are used to. The amount is cut to 4 digits after the comma.
This takes string in a format understood by
BigDecimal(String), for example "0", "1", "0.10", "1.23E3", "1234.5E-5".- Throws:
java.lang.IllegalArgumentException- if you try to specify a value out of range.
-
multiply
public Fiat multiply(long factor)
-
divide
public Fiat divide(long divisor)
-
divideAndRemainder
public Fiat[] divideAndRemainder(long divisor)
-
divide
public long divide(Fiat divisor)
-
isPositive
public boolean isPositive()
Returns true if and only if this instance represents a monetary value greater than zero, otherwise false.
-
isNegative
public boolean isNegative()
Returns true if and only if this instance represents a monetary value less than zero, otherwise false.
-
isZero
public boolean isZero()
Returns true if and only if this instance represents zero monetary value, otherwise false.
-
isGreaterThan
public boolean isGreaterThan(Fiat other)
Returns true if the monetary value represented by this instance is greater than that of the given other Fiat, otherwise false.
-
isLessThan
public boolean isLessThan(Fiat other)
Returns true if the monetary value represented by this instance is less than that of the given other Fiat, otherwise false.
-
negate
public Fiat negate()
-
longValue
public long longValue()
Returns the number of "smallest units" of this monetary value. It's deprecated in favour of accessingvaluedirectly.
-
toFriendlyString
public java.lang.String toFriendlyString()
Returns the value as a 0.12 type string. More digits after the decimal place will be used if necessary, but two will always be present.
-
toPlainString
public java.lang.String toPlainString()
Returns the value as a plain string. The result is unformatted with no trailing zeroes. For instance, a value of 150000 "smallest units" gives an output string of "0.0015".
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-