Package org.bitcoinj.base.utils
Class Fiat
java.lang.Object
org.bitcoinj.base.utils.Fiat
- All Implemented Interfaces:
Comparable<Fiat>
,Monetary
Represents a monetary fiat value. It was decided to not fold this into
Coin
because of type
safety. Fiat values always come with an attached currency code.
This class is immutable.-
Field Summary
Modifier and TypeFieldDescriptionfinal String
static final int
The absolute value of exponent of the value of a "smallest unit" in scientific notation.final long
The number of smallest units of this monetary value. -
Method Summary
Modifier and TypeMethodDescriptionint
divide
(long divisor) long
Fiat[]
divideAndRemainder
(long divisor) boolean
long
getValue()
Returns the number of "smallest units" of this monetary value.int
hashCode()
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.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.boolean
Returns true if and only if this instance represents a monetary value less than zero, otherwise false.boolean
Returns true if and only if this instance represents a monetary value greater than zero, otherwise false.boolean
isZero()
Returns true if and only if this instance represents zero monetary value, otherwise false.long
Returns the number of "smallest units" of this monetary value.multiply
(long factor) negate()
static Fiat
Parses an amount expressed in the way humans are used to.static Fiat
parseFiatInexact
(String currencyCode, String str) Parses an amount expressed in the way humans are used to.int
signum()
int
Returns the absolute value of exponent of the value of a "smallest unit" in scientific notation.Returns the value as a 0.12 type string.Returns the value as a plain string.toString()
static Fiat
-
Field Details
-
SMALLEST_UNIT_EXPONENT
public static final int SMALLEST_UNIT_EXPONENTThe 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:
-
value
public final long valueThe number of smallest units of this monetary value. -
currencyCode
-
-
Method Details
-
valueOf
-
smallestUnitExponent
public int smallestUnitExponent()Description copied from interface:Monetary
Returns 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:
smallestUnitExponent
in interfaceMonetary
-
getValue
public long getValue()Returns the number of "smallest units" of this monetary value. -
getCurrencyCode
-
parseFiat
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:
IllegalArgumentException
- if you try to specify more than 4 digits after the comma, or a value out of range.
-
parseFiatInexact
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:
IllegalArgumentException
- if you try to specify a value out of range.
-
add
-
subtract
-
multiply
-
divide
-
divideAndRemainder
-
divide
-
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
Returns true if the monetary value represented by this instance is greater than that of the given other Fiat, otherwise false. -
isLessThan
Returns true if the monetary value represented by this instance is less than that of the given other Fiat, otherwise false. -
signum
public int signum() -
negate
-
longValue
public long longValue()Returns the number of "smallest units" of this monetary value. It's deprecated in favour of accessingvalue
directly. -
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
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
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<Fiat>
-