Class Decimal
java.lang.Object
java.lang.Number
io.fluxzero.common.Decimal
- All Implemented Interfaces:
Serializable, Comparable<Decimal>
Immutable arbitrary-precision decimal with numerical equality, independent of trailing zeros.
Arithmetic, scale, conversions, rounding and exceptions follow BigDecimal. Decimal-valued results
remain Decimal, including array elements. Both Decimal and BigDecimal operands are accepted. Scale is preserved,
but does not participate in equality or hashing. Equality with other Number types is deliberately false.
JSON uses an exact decimal string; readers also accept numeric tokens. Document indexing uses numeric entries.
Use string constructors or valueOf(long) for exact input; double constructors retain BigDecimal's
exact binary-floating-point conversion semantics. valueOf(double) follows BigDecimal.valueOf(double).
Standard numeric constraints are supported by the Fluxzero validator; third-party providers may require adapters.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DecimalThe value BigDecimal.ONE, as a Decimal.static final intDeprecated.static final intDeprecated.UseRoundingMode.DOWN.static final intDeprecated.UseRoundingMode.FLOOR.static final intDeprecated.static final intDeprecated.static final intDeprecated.UseRoundingMode.HALF_UP.static final intDeprecated.static final intDeprecated.UseRoundingMode.UP.static final DecimalThe value BigDecimal.TEN, as a Decimal.static final DecimalThe value BigDecimal.TWO, as a Decimal.static final DecimalThe value BigDecimal.ZERO, as a Decimal. -
Constructor Summary
ConstructorsConstructorDescriptionDecimal(char[] value) Creates a value withBigDecimal(char[]).Decimal(char[] value, int offset, int length) Creates a value withBigDecimal(char[], int, int).Decimal(char[] value, int offset, int length, MathContext context) Creates a value withBigDecimal(char[], int, int, MathContext).Decimal(char[] value, MathContext context) Creates a value withBigDecimal(char[], MathContext).Decimal(double value) Creates a value withBigDecimal(double).Decimal(double value, MathContext context) Creates a value withBigDecimal(double, MathContext).Decimal(int value) Creates a value withBigDecimal(int).Decimal(int value, MathContext context) Creates a value withBigDecimal(int, MathContext).Decimal(long value) Creates a value withBigDecimal(long).Decimal(long value, MathContext context) Creates a value withBigDecimal(long, MathContext).Creates a value withBigDecimal(String).Decimal(String value, MathContext context) Creates a value withBigDecimal(String, MathContext).Decimal(BigDecimal value) Wraps an immutable BigDecimal without rounding or changing its scale.Decimal(BigInteger value) Creates a value withBigDecimal(BigInteger).Decimal(BigInteger value, int scale) Creates a value withBigDecimal(BigInteger, int).Decimal(BigInteger value, int scale, MathContext context) Creates a value withBigDecimal(BigInteger, int, MathContext).Decimal(BigInteger value, MathContext context) Creates a value withBigDecimal(BigInteger, MathContext). -
Method Summary
Modifier and TypeMethodDescriptionabs()Delegates toBigDecimal.abs().abs(MathContext context) Delegates toBigDecimal.abs(MathContext).Delegates toBigDecimal.add(BigDecimal).add(Decimal other, MathContext context) Delegates toBigDecimal.add(BigDecimal, MathContext).add(BigDecimal other) Delegates toBigDecimal.add(BigDecimal).add(BigDecimal other, MathContext context) Delegates toBigDecimal.add(BigDecimal, MathContext).byteDelegates toBigDecimal.byteValueExact().intDelegates toBigDecimal.compareTo(BigDecimal).intcompareTo(BigDecimal other) Delegates toBigDecimal.compareTo(BigDecimal).Delegates toBigDecimal.divide(BigDecimal).Deprecated.Use the corresponding RoundingMode overload.Deprecated.Use the corresponding RoundingMode overload.divide(Decimal other, int scale, RoundingMode roundingMode) Delegates toBigDecimal.divide(BigDecimal, int, RoundingMode).divide(Decimal other, MathContext context) Delegates toBigDecimal.divide(BigDecimal, MathContext).divide(Decimal other, RoundingMode roundingMode) Delegates toBigDecimal.divide(BigDecimal, RoundingMode).divide(BigDecimal other) Delegates toBigDecimal.divide(BigDecimal).divide(BigDecimal other, int roundingMode) Deprecated.Use the corresponding RoundingMode overload.divide(BigDecimal other, int scale, int roundingMode) Deprecated.Use the corresponding RoundingMode overload.divide(BigDecimal other, int scale, RoundingMode roundingMode) Delegates toBigDecimal.divide(BigDecimal, int, RoundingMode).divide(BigDecimal other, MathContext context) Delegates toBigDecimal.divide(BigDecimal, MathContext).divide(BigDecimal other, RoundingMode roundingMode) Delegates toBigDecimal.divide(BigDecimal, RoundingMode).Decimal[]divideAndRemainder(Decimal other) Delegates toBigDecimal.divideAndRemainder(BigDecimal).Decimal[]divideAndRemainder(Decimal other, MathContext context) Delegates toBigDecimal.divideAndRemainder(BigDecimal, MathContext).Decimal[]divideAndRemainder(BigDecimal other) Delegates toBigDecimal.divideAndRemainder(BigDecimal).Decimal[]divideAndRemainder(BigDecimal other, MathContext context) Delegates toBigDecimal.divideAndRemainder(BigDecimal, MathContext).divideToIntegralValue(Decimal other) Delegates toBigDecimal.divideToIntegralValue(BigDecimal).divideToIntegralValue(Decimal other, MathContext context) divideToIntegralValue(BigDecimal other) Delegates toBigDecimal.divideToIntegralValue(BigDecimal).divideToIntegralValue(BigDecimal other, MathContext context) booleaninthashCode()intDelegates toBigDecimal.intValueExact().longDelegates toBigDecimal.longValueExact().Delegates toBigDecimal.max(BigDecimal).max(BigDecimal other) Delegates toBigDecimal.max(BigDecimal).Delegates toBigDecimal.min(BigDecimal).min(BigDecimal other) Delegates toBigDecimal.min(BigDecimal).movePointLeft(int distance) Delegates toBigDecimal.movePointLeft(int).movePointRight(int distance) Delegates toBigDecimal.movePointRight(int).Delegates toBigDecimal.multiply(BigDecimal).multiply(Decimal other, MathContext context) Delegates toBigDecimal.multiply(BigDecimal, MathContext).multiply(BigDecimal other) Delegates toBigDecimal.multiply(BigDecimal).multiply(BigDecimal other, MathContext context) Delegates toBigDecimal.multiply(BigDecimal, MathContext).negate()Delegates toBigDecimal.negate().negate(MathContext context) Delegates toBigDecimal.negate(MathContext).plus()Delegates toBigDecimal.plus().plus(MathContext context) Delegates toBigDecimal.plus(MathContext).pow(int exponent) Delegates toBigDecimal.pow(int).pow(int exponent, MathContext context) Delegates toBigDecimal.pow(int, MathContext).intDelegates toBigDecimal.precision().Delegates toBigDecimal.remainder(BigDecimal).remainder(Decimal other, MathContext context) Delegates toBigDecimal.remainder(BigDecimal, MathContext).remainder(BigDecimal other) Delegates toBigDecimal.remainder(BigDecimal).remainder(BigDecimal other, MathContext context) Delegates toBigDecimal.remainder(BigDecimal, MathContext).round(MathContext context) Delegates toBigDecimal.round(MathContext).intscale()Delegates toBigDecimal.scale().scaleByPowerOfTen(int exponent) Delegates toBigDecimal.scaleByPowerOfTen(int).setScale(int scale) Delegates toBigDecimal.setScale(int).setScale(int scale, int roundingMode) Deprecated.Use the corresponding RoundingMode overload.setScale(int scale, RoundingMode roundingMode) Delegates toBigDecimal.setScale(int, RoundingMode).shortDelegates toBigDecimal.shortValueExact().intsignum()Delegates toBigDecimal.signum().sqrt(MathContext context) Delegates toBigDecimal.sqrt(MathContext).Delegates toBigDecimal.stripTrailingZeros().Delegates toBigDecimal.subtract(BigDecimal).subtract(Decimal other, MathContext context) Delegates toBigDecimal.subtract(BigDecimal, MathContext).subtract(BigDecimal other) Delegates toBigDecimal.subtract(BigDecimal).subtract(BigDecimal other, MathContext context) Delegates toBigDecimal.subtract(BigDecimal, MathContext).Returns the underlying immutable value, preserving its scale.Delegates toBigDecimal.toBigInteger().Delegates toBigDecimal.toBigIntegerExact().Delegates toBigDecimal.toEngineeringString().Delegates toBigDecimal.toPlainString().toString()ulp()Delegates toBigDecimal.ulp().Delegates toBigDecimal.unscaledValue().static DecimalvalueOf(double value) Delegates toBigDecimal.valueOf(double).static DecimalvalueOf(long value) Delegates toBigDecimal.valueOf(long).static DecimalvalueOf(long value, int scale) Delegates toBigDecimal.valueOf(long, int).Methods inherited from class Number
byteValue, doubleValue, floatValue, intValue, longValue, shortValue
-
Field Details
-
ZERO
The value BigDecimal.ZERO, as a Decimal. -
ONE
The value BigDecimal.ONE, as a Decimal. -
TWO
The value BigDecimal.TWO, as a Decimal. -
TEN
The value BigDecimal.TEN, as a Decimal. -
ROUND_UP
-
ROUND_DOWN
-
ROUND_CEILING
-
ROUND_FLOOR
-
ROUND_HALF_UP
-
ROUND_HALF_DOWN
Deprecated.- See Also:
-
ROUND_HALF_EVEN
Deprecated.- See Also:
-
ROUND_UNNECESSARY
Deprecated.- See Also:
-
-
Constructor Details
-
Decimal
Wraps an immutable BigDecimal without rounding or changing its scale. -
Decimal
public Decimal(char[] value, int offset, int length) Creates a value withBigDecimal(char[], int, int). -
Decimal
Creates a value withBigDecimal(char[], int, int, MathContext). -
Decimal
public Decimal(char[] value) Creates a value withBigDecimal(char[]). -
Decimal
Creates a value withBigDecimal(char[], MathContext). -
Decimal
Creates a value withBigDecimal(String). -
Decimal
Creates a value withBigDecimal(String, MathContext). -
Decimal
public Decimal(double value) Creates a value withBigDecimal(double). -
Decimal
Creates a value withBigDecimal(double, MathContext). -
Decimal
Creates a value withBigDecimal(BigInteger). -
Decimal
Creates a value withBigDecimal(BigInteger, MathContext). -
Decimal
Creates a value withBigDecimal(BigInteger, int). -
Decimal
Creates a value withBigDecimal(BigInteger, int, MathContext). -
Decimal
public Decimal(int value) Creates a value withBigDecimal(int). -
Decimal
Creates a value withBigDecimal(int, MathContext). -
Decimal
public Decimal(long value) Creates a value withBigDecimal(long). -
Decimal
Creates a value withBigDecimal(long, MathContext).
-
-
Method Details
-
toBigDecimal
Returns the underlying immutable value, preserving its scale. -
valueOf
Delegates toBigDecimal.valueOf(long, int). Decimal results retain this value type. -
valueOf
Delegates toBigDecimal.valueOf(long). Decimal results retain this value type. -
valueOf
Delegates toBigDecimal.valueOf(double). Decimal results retain this value type. -
add
Delegates toBigDecimal.add(BigDecimal). Decimal results retain this value type. -
add
Delegates toBigDecimal.add(BigDecimal). Decimal results retain this value type. -
add
Delegates toBigDecimal.add(BigDecimal, MathContext). Decimal results retain this value type. -
add
Delegates toBigDecimal.add(BigDecimal, MathContext). Decimal results retain this value type. -
subtract
Delegates toBigDecimal.subtract(BigDecimal). Decimal results retain this value type. -
subtract
Delegates toBigDecimal.subtract(BigDecimal). Decimal results retain this value type. -
subtract
Delegates toBigDecimal.subtract(BigDecimal, MathContext). Decimal results retain this value type. -
subtract
Delegates toBigDecimal.subtract(BigDecimal, MathContext). Decimal results retain this value type. -
multiply
Delegates toBigDecimal.multiply(BigDecimal). Decimal results retain this value type. -
multiply
Delegates toBigDecimal.multiply(BigDecimal). Decimal results retain this value type. -
multiply
Delegates toBigDecimal.multiply(BigDecimal, MathContext). Decimal results retain this value type. -
multiply
Delegates toBigDecimal.multiply(BigDecimal, MathContext). Decimal results retain this value type. -
divide
Deprecated.Use the corresponding RoundingMode overload.Delegates toBigDecimal.divide(BigDecimal, int, int). Decimal results retain this value type. -
divide
Deprecated.Use the corresponding RoundingMode overload.Delegates toBigDecimal.divide(BigDecimal, int, int). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, int, RoundingMode). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, int, RoundingMode). Decimal results retain this value type. -
divide
Deprecated.Use the corresponding RoundingMode overload.Delegates toBigDecimal.divide(BigDecimal, int). Decimal results retain this value type. -
divide
Deprecated.Use the corresponding RoundingMode overload.Delegates toBigDecimal.divide(BigDecimal, int). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, RoundingMode). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, RoundingMode). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, MathContext). Decimal results retain this value type. -
divide
Delegates toBigDecimal.divide(BigDecimal, MathContext). Decimal results retain this value type. -
divideToIntegralValue
Delegates toBigDecimal.divideToIntegralValue(BigDecimal). Decimal results retain this value type. -
divideToIntegralValue
Delegates toBigDecimal.divideToIntegralValue(BigDecimal). Decimal results retain this value type. -
divideToIntegralValue
Delegates toBigDecimal.divideToIntegralValue(BigDecimal, MathContext). Decimal results retain this value type. -
divideToIntegralValue
Delegates toBigDecimal.divideToIntegralValue(BigDecimal, MathContext). Decimal results retain this value type. -
remainder
Delegates toBigDecimal.remainder(BigDecimal). Decimal results retain this value type. -
remainder
Delegates toBigDecimal.remainder(BigDecimal). Decimal results retain this value type. -
remainder
Delegates toBigDecimal.remainder(BigDecimal, MathContext). Decimal results retain this value type. -
remainder
Delegates toBigDecimal.remainder(BigDecimal, MathContext). Decimal results retain this value type. -
divideAndRemainder
Delegates toBigDecimal.divideAndRemainder(BigDecimal). Decimal results retain this value type. -
divideAndRemainder
Delegates toBigDecimal.divideAndRemainder(BigDecimal). Decimal results retain this value type. -
divideAndRemainder
Delegates toBigDecimal.divideAndRemainder(BigDecimal, MathContext). Decimal results retain this value type. -
divideAndRemainder
Delegates toBigDecimal.divideAndRemainder(BigDecimal, MathContext). Decimal results retain this value type. -
sqrt
Delegates toBigDecimal.sqrt(MathContext). Decimal results retain this value type. -
pow
Delegates toBigDecimal.pow(int). Decimal results retain this value type. -
pow
Delegates toBigDecimal.pow(int, MathContext). Decimal results retain this value type. -
abs
Delegates toBigDecimal.abs(). Decimal results retain this value type. -
abs
Delegates toBigDecimal.abs(MathContext). Decimal results retain this value type. -
negate
Delegates toBigDecimal.negate(). Decimal results retain this value type. -
negate
Delegates toBigDecimal.negate(MathContext). Decimal results retain this value type. -
plus
Delegates toBigDecimal.plus(). Decimal results retain this value type. -
plus
Delegates toBigDecimal.plus(MathContext). Decimal results retain this value type. -
signum
public int signum()Delegates toBigDecimal.signum(). -
scale
public int scale()Delegates toBigDecimal.scale(). -
precision
public int precision()Delegates toBigDecimal.precision(). -
unscaledValue
Delegates toBigDecimal.unscaledValue(). -
round
Delegates toBigDecimal.round(MathContext). Decimal results retain this value type. -
setScale
Delegates toBigDecimal.setScale(int, RoundingMode). Decimal results retain this value type. -
setScale
Deprecated.Use the corresponding RoundingMode overload.Delegates toBigDecimal.setScale(int, int). Decimal results retain this value type. -
setScale
Delegates toBigDecimal.setScale(int). Decimal results retain this value type. -
movePointLeft
Delegates toBigDecimal.movePointLeft(int). Decimal results retain this value type. -
movePointRight
Delegates toBigDecimal.movePointRight(int). Decimal results retain this value type. -
scaleByPowerOfTen
Delegates toBigDecimal.scaleByPowerOfTen(int). Decimal results retain this value type. -
stripTrailingZeros
Delegates toBigDecimal.stripTrailingZeros(). Decimal results retain this value type. -
compareTo
Delegates toBigDecimal.compareTo(BigDecimal). -
compareTo
Delegates toBigDecimal.compareTo(BigDecimal).- Specified by:
compareToin interfaceComparable<Decimal>
-
min
Delegates toBigDecimal.min(BigDecimal). Decimal results retain this value type. -
min
Delegates toBigDecimal.min(BigDecimal). Decimal results retain this value type. -
max
Delegates toBigDecimal.max(BigDecimal). Decimal results retain this value type. -
max
Delegates toBigDecimal.max(BigDecimal). Decimal results retain this value type. -
toEngineeringString
Delegates toBigDecimal.toEngineeringString(). -
toPlainString
Delegates toBigDecimal.toPlainString(). -
toBigInteger
Delegates toBigDecimal.toBigInteger(). -
toBigIntegerExact
Delegates toBigDecimal.toBigIntegerExact(). -
longValueExact
public long longValueExact()Delegates toBigDecimal.longValueExact(). -
intValueExact
public int intValueExact()Delegates toBigDecimal.intValueExact(). -
shortValueExact
public short shortValueExact()Delegates toBigDecimal.shortValueExact(). -
byteValueExact
public byte byteValueExact()Delegates toBigDecimal.byteValueExact(). -
ulp
Delegates toBigDecimal.ulp(). Decimal results retain this value type. -
equals
-
hashCode
-
toString
-
RoundingMode.CEILING.