public final class FixedScaleDecimal extends Object implements Serializable, Comparable<FixedScaleDecimal>
Decimal with a fixed scale.
This is a lightweight wrapper for Decimal that ensures the scale is fixed, between 0 and 18.
It is most useful for monetary values.
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(FixedScaleDecimal other) |
Decimal |
decimal()
Gets the underlying decimal.
|
boolean |
equals(Object obj) |
int |
fixedScale()
Gets the fixed scale.
|
int |
hashCode() |
FixedScaleDecimal |
map(UnaryOperator<Decimal> fn)
Maps this value using the maths operations of
Decimal. |
static FixedScaleDecimal |
of(Decimal decimal,
int fixedScale)
Obtains an instance from a decimal and scale.
|
static FixedScaleDecimal |
parse(String str)
Parses an instance from a
String. |
BigDecimal |
toBigDecimal()
Gets the value as a
BigDecimal with the fixed scale. |
String |
toString()
Returns the formal string representation of the fixed scale decimal.
|
public static FixedScaleDecimal of(Decimal decimal, int fixedScale)
decimal - the underlying decimalfixedScale - the fixed scale, equal or greater than the scale of the decimalpublic static FixedScaleDecimal parse(String str)
String.str - the stringNumberFormatException - if the string cannot be parsedIllegalArgumentException - if the value is too largepublic Decimal decimal()
The decimal may have a smaller scale, but it will not have a larger scale.
public int fixedScale()
public FixedScaleDecimal map(UnaryOperator<Decimal> fn)
Decimal.
The result must have a scale equal or less than the fixed scale.
fn - the function to applyIllegalArgumentException - if the result is too largepublic BigDecimal toBigDecimal()
BigDecimal with the fixed scale.public int compareTo(FixedScaleDecimal other)
compareTo in interface Comparable<FixedScaleDecimal>Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.