Top Description Fields Constructors Methods
org.javamoney.moneta.spi

public final Class DefaultNumberValue

extends NumberValue
Class Inheritance
Imports
javax.money.NumberValue, java.math.BigDecimal, .MathContext, java.util.Objects

Default implementation of NumberValue based on BigDecimal.
Authors
Anatole Tresch, Werner Keil

Field Summary

Modifier and TypeField and Description
private final Number
number

The numeric value.

public static final NumberValue
ONE

The value 1, with a scale of 0.

private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public double
doubleValue()

Implements abstract java.lang.Number.doubleValue.

Returns the value of the specified number as a double.

public double
doubleValueExact()

Implements abstract javax.money.NumberValue.doubleValueExact.

Access the numeric value as double.

public float
floatValue()

Implements abstract java.lang.Number.floatValue.

Returns the value of the specified number as a float.

public long
getAmountFractionDenominator()

Implements abstract javax.money.NumberValue.getAmountFractionDenominator.

This method allows to extract the denominator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
public long
getAmountFractionNumerator()

Implements abstract javax.money.NumberValue.getAmountFractionNumerator.

This method allows to extract the numerator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
protected static BigDecimal

Returns:

the corresponding BigDecimal
getBigDecimal
(Number
the number type
num
)
Deprecated will be removed.

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

public Class<?>
getNumberType()

Implements abstract javax.money.NumberValue.getNumberType.

Get the numeric implementation type, that is the base of this number.

public int
getPrecision()

Implements abstract javax.money.NumberValue.getPrecision.

Returns the precision of this MonetaryAmount.

public int
getScale()

Implements abstract javax.money.NumberValue.getScale.

Returns the scale of this MonetaryAmount.

public int
intValue()

Implements abstract java.lang.Number.intValue.

Returns the value of the specified number as an int.

public int
intValueExact()

Implements abstract javax.money.NumberValue.intValueExact.

Access the numeric value as int.

public long
longValue()

Implements abstract java.lang.Number.longValue.

Returns the value of the specified number as a long.

public long
longValueExact()

Implements abstract javax.money.NumberValue.longValueExact.

Access the numeric value as long.

public <T extends Number> T
numberValue(Class<T> numberType)

Implements abstract javax.money.NumberValue.numberValue.

Access the numeric value as Number.

public <T extends Number> T
numberValueExact(Class<T> numberType)

Implements abstract javax.money.NumberValue.numberValueExact.

Access the numeric value as Number.

public static NumberValue

Returns:

A new instance of NumberValue.
of
(Number
The numeric part, not null.
number
)

Creates a new instance of NumberValue, using the given number.

public NumberValue
round(MathContext mathContext)

Implements abstract javax.money.NumberValue.round.

Access the current NumberValue rounded using the given java.math.MathContext.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from javax.money.NumberValue:
compareTo

Field Detail

numberback to summary
private final Number number

The numeric value.

ONEback to summary
public static final NumberValue ONE

The value 1, with a scale of 0.
Backed by BigDecimal#ONE

Since
0.8
serialVersionUIDback to summary
private static final long serialVersionUID

Hides javax.money.NumberValue.serialVersionUID.

serialVersionUID.

Constructor Detail

DefaultNumberValueback to summary
public DefaultNumberValue(Number number)

Method Detail

doubleValueback to summary
public double doubleValue()

Implements abstract java.lang.Number.doubleValue.

Doc from java.lang.Number.doubleValue.

Returns the value of the specified number as a double.

Annotations
@Override
doubleValueExactback to summary
public double doubleValueExact()

Implements abstract javax.money.NumberValue.doubleValueExact.

Doc from javax.money.NumberValue.doubleValueExact.

Access the numeric value as double. Hereby no truncation will be performed to fit the value into the target data type.

Annotations
@Override
floatValueback to summary
public float floatValue()

Implements abstract java.lang.Number.floatValue.

Doc from java.lang.Number.floatValue.

Returns the value of the specified number as a float.

Annotations
@Override
getAmountFractionDenominatorback to summary
public long getAmountFractionDenominator()

Implements abstract javax.money.NumberValue.getAmountFractionDenominator.

Doc from javax.money.NumberValue.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
.
Annotations
@Override
getAmountFractionNumeratorback to summary
public long getAmountFractionNumerator()

Implements abstract javax.money.NumberValue.getAmountFractionNumerator.

Doc from javax.money.NumberValue.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
.
Annotations
@Override
getBigDecimalback to summary
protected static BigDecimal getBigDecimal(Number num)

Deprecated

will be removed.

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

Parameters
num:Number

the number type

Returns:BigDecimal

the corresponding BigDecimal

Annotations
@Deprecated
getNumberTypeback to summary
public Class<?> getNumberType()

Implements abstract javax.money.NumberValue.getNumberType.

Doc from javax.money.NumberValue.getNumberType.

Get the numeric implementation type, that is the base of this number.

Annotations
@Override
getPrecisionback to summary
public int getPrecision()

Implements abstract javax.money.NumberValue.getPrecision.

Doc from javax.money.NumberValue.getPrecision.

Returns the precision of this MonetaryAmount. (The precision is the number of digits in the unscaled value.)

The precision of a zero value is 1.

Annotations
@Override
getScaleback to summary
public int getScale()

Implements abstract javax.money.NumberValue.getScale.

Doc from javax.money.NumberValue.getScale.

Returns the scale of this 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.

Annotations
@Override
intValueback to summary
public int intValue()

Implements abstract java.lang.Number.intValue.

Doc from java.lang.Number.intValue.

Returns the value of the specified number as an int.

Annotations
@Override
intValueExactback to summary
public int intValueExact()

Implements abstract javax.money.NumberValue.intValueExact.

Doc from javax.money.NumberValue.intValueExact.

Access the numeric value as int. Hereby no truncation will be performed to fit the value into the target data type.

Annotations
@Override
longValueback to summary
public long longValue()

Implements abstract java.lang.Number.longValue.

Doc from java.lang.Number.longValue.

Returns the value of the specified number as a long.

Annotations
@Override
longValueExactback to summary
public long longValueExact()

Implements abstract javax.money.NumberValue.longValueExact.

Doc from javax.money.NumberValue.longValueExact.

Access the numeric value as long. Hereby no truncation will be performed to fit the value into the target data type.

Annotations
@Override
numberValueback to summary
public <T extends Number> T numberValue(Class<T> numberType)

Implements abstract javax.money.NumberValue.numberValue.

Doc from javax.money.NumberValue.numberValue.

Access the numeric value as Number. Hereby truncation may be performed as needed to fit the value into the target data type.

Annotations
@Override
numberValueExactback to summary
public <T extends Number> T numberValueExact(Class<T> numberType)

Implements abstract javax.money.NumberValue.numberValueExact.

Doc from javax.money.NumberValue.numberValueExact.

Access the numeric value as Number. Hereby no truncation will be performed to fit the value into the target data type.

Annotations
@Override
ofback to summary
public static NumberValue of(Number number)

Creates a new instance of NumberValue, using the given number.

Parameters
number:Number

The numeric part, not null.

Returns:NumberValue

A new instance of NumberValue.

roundback to summary
public NumberValue round(MathContext mathContext)

Implements abstract javax.money.NumberValue.round.

Doc from javax.money.NumberValue.round.

Access the current NumberValue rounded using the given java.math.MathContext.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override