public class DefaultNumberValue
extends javax.money.NumberValue
NumberValue
based on BigDecimal
.Modifier and Type | Field and Description |
---|---|
static javax.money.NumberValue |
ONE
The value 1, with a scale of 0.
|
Constructor and Description |
---|
DefaultNumberValue(java.lang.Number number) |
Modifier and Type | Method and Description |
---|---|
double |
doubleValue() |
double |
doubleValueExact()
Access the numeric value as
double . |
float |
floatValue() |
protected static java.math.BigDecimal |
getBigDecimal(java.lang.Number num)
Creates a
BigDecimal from the given Number doing the valid conversion
depending the type given. |
java.lang.Class<?> |
getNumberType()
Get the numeric implementation type, that is the base of this number.
|
int |
getPrecision()
Returns the precision of this
MonetaryAmount . |
int |
getScale()
Returns the scale of this
MonetaryAmount . |
int |
intValue() |
int |
intValueExact()
Access the numeric value as
int . |
long |
longValue() |
long |
longValueExact()
Access the numeric value as
long . |
<T extends java.lang.Number> |
numberValue(java.lang.Class<T> numberType)
Access the numeric value as
Number . |
<T extends java.lang.Number> |
numberValueExact(java.lang.Class<T> numberType)
Access the numeric value as
Number . |
static javax.money.NumberValue |
of(java.lang.Number number)
Creates a new instance of
NumberValue , using the given number. |
java.lang.String |
toString() |
public static final javax.money.NumberValue ONE
BigDecimal.ONE
public double doubleValue()
doubleValue
in class java.lang.Number
public double doubleValueExact()
javax.money.NumberValue
double
. Hereby no truncation will be performed to fit the
value into the target data type.doubleValueExact
in class javax.money.NumberValue
MonetaryAmount
.public float floatValue()
floatValue
in class java.lang.Number
protected static java.math.BigDecimal getBigDecimal(java.lang.Number num)
BigDecimal
from the given Number
doing the valid conversion
depending the type given.num
- the number typeBigDecimal
public java.lang.Class<?> getNumberType()
javax.money.NumberValue
getNumberType
in class javax.money.NumberValue
null
.public int getPrecision()
javax.money.NumberValue
MonetaryAmount
. (The precision is the number of
digits in the unscaled value.)
The precision of a zero value is 1.getPrecision
in class javax.money.NumberValue
MonetaryAmount
.public int getScale()
javax.money.NumberValue
MonetaryAmount
. If zero or positive, the scale is
the number of digits to the right of the decimal point. If negative, the unscaled value of
the number is multiplied by ten to the power of the negation of the scale. For example, a
scale of -3
means the unscaled value is multiplied by 1000.getScale
in class javax.money.NumberValue
MonetaryAmount
.public int intValue()
intValue
in class java.lang.Number
public int intValueExact()
javax.money.NumberValue
int
. Hereby no truncation will be performed to fit the
value into the target data type.intValueExact
in class javax.money.NumberValue
MonetaryAmount
.public long longValue()
longValue
in class java.lang.Number
public long longValueExact()
javax.money.NumberValue
long
. Hereby no truncation will be performed to fit the
value into the target data type.longValueExact
in class javax.money.NumberValue
MonetaryAmount
.public <T extends java.lang.Number> T numberValue(java.lang.Class<T> numberType)
javax.money.NumberValue
Number
. Hereby truncation may be performed as needed to
fit the value into the target data type.numberValue
in class javax.money.NumberValue
numberType
- The concrete number class to be returned. Basically the following Number types,
must be supported if available on the corresponding runtime platform:
java.lang.Long
java.lang.Double
java.lang.Number
java.math.BigInteger
, currently not available on all platforms.java.math.BigDecimal
, currently not available on all platforms.MonetaryAmount
.public <T extends java.lang.Number> T numberValueExact(java.lang.Class<T> numberType)
javax.money.NumberValue
Number
. Hereby no truncation will be performed to fit the
value into the target data type.numberValueExact
in class javax.money.NumberValue
numberType
- The concrete number class to be returned. Basically the following Number types,
must be supported if available on the corresponding runtime platform:
java.lang.Long
java.lang.Double
java.lang.Number
java.math.BigInteger
, currently not available on all platforms.java.math.BigDecimal
, currently not available on all platforms.MonetaryAmount
.public static javax.money.NumberValue of(java.lang.Number number)
NumberValue
, using the given number.number
- The numeric part, not null.NumberValue
.public java.lang.String toString()
toString
in class java.lang.Object