public abstract class NumberValue extends Number implements Comparable<NumberValue>
MonetaryAmount
. The classs extends
Number
for maximal compatibility with the JDK but also adds additional functionality to
overcome some of the pitfalls of the JDK's Number class.
Implementations of this interface must be
Constructor and Description |
---|
NumberValue() |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(NumberValue other) |
abstract double |
doubleValueExact()
Access the numeric value as
double . |
abstract long |
getAmountFractionDenominator()
This method allows to extract the denominator part of the current fraction, hereby given
w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:
!(w<0 && n>0) and
!(w>0 && n<0) and
d>0 and
|n| < d // || = absolute value
. |
abstract long |
getAmountFractionNumerator()
This method allows to extract the numerator part of the current fraction, hereby given
w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:
!(w<0 && n>0) and
!(w>0 && n<0) and
d>0 and
|n| < d // || = absolute value
. |
abstract Class<?> |
getNumberType()
Get the numeric implementation type, that is the base of this number.
|
abstract int |
getPrecision()
Returns the precision of this
MonetaryAmount . |
abstract int |
getScale()
Returns the scale of this
MonetaryAmount . |
abstract int |
intValueExact()
Access the numeric value as
int . |
abstract long |
longValueExact()
Access the numeric value as
long . |
abstract <T extends Number> |
numberValue(Class<T> numberType)
Access the numeric value as
Number . |
abstract <T extends Number> |
numberValueExact(Class<T> numberType)
Access the numeric value as
Number . |
abstract NumberValue |
round(MathContext mathContext)
Access the current NumberValue rounded using the given
MathContext . |
byteValue, doubleValue, floatValue, intValue, longValue, shortValue
public abstract Class<?> getNumberType()
null
.public abstract int getPrecision()
MonetaryAmount
. (The precision is the number of
digits in the unscaled value.)
The precision of a zero value is 1.
MonetaryAmount
.public abstract int getScale()
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.MonetaryAmount
.public abstract int intValueExact()
int
. Hereby no truncation will be performed to fit the
value into the target data type.MonetaryAmount
.ArithmeticException
- If the value must be truncated to fit the target datatype.public abstract long longValueExact()
long
. Hereby no truncation will be performed to fit the
value into the target data type.MonetaryAmount
.ArithmeticException
- If the value must be truncated to fit the target datatype.public abstract double doubleValueExact()
double
. Hereby no truncation will be performed to fit the
value into the target data type.MonetaryAmount
.ArithmeticException
- If the value must be truncated to fit the target datatype.public abstract <T extends Number> T numberValue(Class<T> numberType)
Number
. Hereby truncation may be performed as needed to
fit the value into the target data type.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 abstract NumberValue round(MathContext mathContext)
MathContext
.mathContext
- the MathContext
to be applied.BigDecimal.round(java.math.MathContext)
public abstract <T extends Number> T numberValueExact(Class<T> numberType)
Number
. Hereby no truncation will be performed to fit the
value into the target data type.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
.ArithmeticException
- If the value must be truncated to fit the target datatype.public abstract long getAmountFractionNumerator()
w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:
!(w<0 && n>0) and
!(w>0 && n<0) and
d>0 and
|n| < d // || = absolute value
.public abstract long getAmountFractionDenominator()
w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:
!(w<0 && n>0) and
!(w>0 && n<0) and
d>0 and
|n| < d // || = absolute value
.public int compareTo(NumberValue other)
compareTo
in interface Comparable<NumberValue>
Copyright © 2012–2016 JSR 354 - Expert Group. All rights reserved.