S - the scale metrics type associated with this Decimalpublic interface Decimal<S extends ScaleMetrics> extends Comparable<Decimal<S>>
BigDecimal. A Decimal number can be immutable or mutable and it
is based on an underlying unscaled long value and a fixed scale. The scale defines the
number of digits to the right of the decimal point. If the scale is f then the value represented by a
Decimal instance is (unscaledValue × 10-f).
Scale of Result and Operands
The result of an arithmetic operation is generally of the same scale as this Decimal unless otherwise indicated.
Decimal operands of arithmetic operations are typically also of the same scale as this Decimal. Scale compatibility
of Decimal operands is enforced through the generic ScaleMetrics parameter <S>.
Operands involving Type Conversion
For convenience, arithmetic operations with other data types are sometimes also provided. Such operations usually
perform a value conversion into a Decimal of the current scale before performing the actual operation.
Rounding
If the result of an arithmetic operation cannot be represented exactly in the scale of this Decimal, it is rounded to
the least significant digit. HALF_UP rounding is used by default if no other rounding
mode is explicitly specified. Note that in a few exceptional cases HALF_EVEN rounding
is used by default to comply with inherited specification constraints (e.g. see doubleValue(),
floatValue() etc.). The documentation of operations which involve rounding indicate the rounding mode that
is applied.
Overflows
Operations with Decimal values can lead to overflows in marked contrast to the BigDecimal. This is a direct
consequence of the construction of a Decimal value on the basis of a long value. Unless otherwise indicated
operations silently truncate overflows by default. This choice has been made for performance reasons and because Java
programmers are already familiar with this behavior from operations with primitive integer types. If this behavior is
inappropriate for an application, exceptions in overflow situations can be enforced through an optional
OverflowMode or TruncationPolicy argument. Some operations like conversion operations or arithmetic
operations involving conversion always throw an exception if an overflow occurs. The documentation of
operations which can cause an overflow always indicates the exact overflow behavior.
All methods for this interface throw NullPointerException when passed a null object reference for any
input parameter.
| Modifier and Type | Method and Description |
|---|---|
Decimal<S> |
abs()
Returns a
Decimal whose value is the absolute value of this Decimal. |
Decimal<S> |
abs(OverflowMode overflowMode)
Returns a
Decimal whose value is the absolute value of this Decimal. |
Decimal<S> |
add(Decimal<?> augend,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this + augend). |
Decimal<S> |
add(Decimal<?> augend,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this + augend). |
Decimal<S> |
add(Decimal<S> augend)
Returns a
Decimal whose value is (this + augend). |
Decimal<S> |
add(Decimal<S> augend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this + augend). |
Decimal<S> |
add(double augend)
Returns a
Decimal whose value is (this + augend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
add(double augend,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this + augend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
add(long augend)
Returns a
Decimal whose value is (this + augend) after converting the given long value to
the scale of this Decimal. |
Decimal<S> |
add(long augend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this + augend) after converting the given long value to
the scale of this Decimal. |
Decimal<S> |
addSquared(Decimal<S> value)
Returns a
Decimal whose value is (this + value2). |
Decimal<S> |
addSquared(Decimal<S> value,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this + value2). |
Decimal<S> |
addSquared(Decimal<S> value,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this + value2). |
Decimal<S> |
addUnscaled(long unscaledAugend)
Returns a
Decimal whose value is (this + unscaledAugend × 10-scale) with the
scale of this Decimal. |
Decimal<S> |
addUnscaled(long unscaledAugend,
int scale)
Returns a
Decimal whose value is (this + unscaledAugend × 10-scale). |
Decimal<S> |
addUnscaled(long unscaledAugend,
int scale,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this + unscaledAugend × 10-scale). |
Decimal<S> |
addUnscaled(long unscaledAugend,
int scale,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this + unscaledAugend × 10-scale). |
Decimal<S> |
addUnscaled(long unscaledAugend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this + unscaledAugend × 10-scale) with the
scale of this Decimal. |
Decimal<S> |
avg(Decimal<S> val)
Returns the average of this
Decimal and val. |
Decimal<S> |
avg(Decimal<S> val,
RoundingMode roundingMode)
Returns the average of this
Decimal and val. |
byte |
byteValue()
Returns the value of this
Decimal as a byte after a narrowing primitive conversion. |
byte |
byteValueExact()
Converts this
Decimal to a byte, checking for lost information. |
int |
compareTo(Decimal<S> other)
Compares two
Decimal objects numerically. |
int |
compareToNumerically(Decimal<?> other)
Compares this
Decimal with the specified Decimal. |
Decimal<S> |
divide(Decimal<S> divisor)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divide(Decimal<S> divisor,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divide(Decimal<S> divisor,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divide(double divisor)
Returns a
Decimal whose value is (this / divisor) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
divide(double divisor,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / divisor) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
divide(long divisor)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divide(long divisor,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divide(long divisor,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S>[] |
divideAndRemainder(Decimal<S> divisor)
Returns a two-element
Decimal array containing the result of divideToIntegralValue followed by
the result of remainder on the two operands. |
Decimal<S>[] |
divideAndRemainder(Decimal<S> divisor,
OverflowMode overflowMode)
Returns a two-element
Decimal array containing the result of divideToIntegralValue followed by
the result of remainder on the two operands. |
Decimal<S> |
divideBy(Decimal<?> divisor)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divideBy(Decimal<?> divisor,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divideBy(Decimal<?> divisor,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / divisor). |
Decimal<S> |
divideByPowerOfTen(int n)
Returns a
Decimal whose value is (this / 10n) . |
Decimal<S> |
divideByPowerOfTen(int n,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / 10n) . |
Decimal<S> |
divideByPowerOfTen(int n,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / 10n) . |
Decimal<S> |
divideExact(Decimal<S> divisor)
Returns a
Decimal whose value is (this / divisor), checking for lost information. |
Decimal<S> |
divideToIntegralValue(Decimal<S> divisor)
Returns a
Decimal whose value is (this / divisor) rounded down to the next integer. |
Decimal<S> |
divideToIntegralValue(Decimal<S> divisor,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this / divisor) rounded down to the next integer. |
long |
divideToLongValue(Decimal<S> divisor)
Returns a
Decimal whose value (this / divisor) rounded down to the next long value. |
long |
divideToLongValue(Decimal<S> divisor,
OverflowMode overflowMode)
Returns a
Decimal whose value (this / divisor) rounded down to the next long value. |
Decimal<S> |
divideTruncate(Decimal<S> divisor)
Returns a
Decimal whose value is (this / divisor) rounded down. |
Decimal<S> |
divideUnscaled(long unscaledDivisor)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. |
Decimal<S> |
divideUnscaled(long unscaledDivisor,
int scale)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)). |
Decimal<S> |
divideUnscaled(long unscaledDivisor,
int scale,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)). |
Decimal<S> |
divideUnscaled(long unscaledDivisor,
int scale,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)). |
Decimal<S> |
divideUnscaled(long unscaledDivisor,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. |
Decimal<S> |
divideUnscaled(long unscaledDivisor,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. |
double |
doubleValue()
Converts this
Decimal to a double. |
double |
doubleValue(RoundingMode roundingMode)
Converts this
Decimal to a double using the specified rounding mode if the Decimal value can not
be exactly represented as a double value. |
boolean |
equals(Object obj)
Compares this Decimal to the specified object.
|
float |
floatValue()
Converts this
Decimal to a float. |
float |
floatValue(RoundingMode roundingMode)
Converts this
Decimal to a float using the specified rounding mode if the Decimal value can not
be exactly represented as a float value. |
Decimal<S> |
fractionalPart()
Returns a
Decimal whose value represents the fractional part of (this) value. |
DecimalFactory<S> |
getFactory()
Returns the factory that can be used to create other Decimal values of the same scale as
this Decimal. |
int |
getScale()
Returns the scale associated with this Decimal.
|
S |
getScaleMetrics()
Returns the metrics associated with the scale of this Decimal.
|
int |
hashCode()
Returns a hash code for this
Decimal. |
Decimal<S> |
integralPart()
Returns a
Decimal whose value represents the integral part of this Decimal. |
int |
intValue()
Converts this
Decimal to an int. |
int |
intValueExact()
Converts this
Decimal to an int, checking for lost information. |
Decimal<S> |
invert()
Returns a
Decimal whose value is (1 / this). |
Decimal<S> |
invert(RoundingMode roundingMode)
Returns a
Decimal whose value is (1 / this). |
Decimal<S> |
invert(TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (1 / this). |
boolean |
isBetweenZeroAndMinusOne()
Returns true if this
Decimal is between zero (inclusive) and minus one (exclusive). |
boolean |
isBetweenZeroAndOne()
Returns true if this
Decimal is between zero (inclusive) and one (exclusive). |
boolean |
isEqualTo(Decimal<S> other)
Compares this
Decimal with the specified Decimal and returns true if the two are numerically
equal. |
boolean |
isEqualToNumerically(Decimal<?> other)
Compares this
Decimal with the specified Decimal and returns true if the two are numerically
equal. |
boolean |
isGreaterThan(Decimal<S> other)
Compares this
Decimal with the specified Decimal and returns true if this Decimal is numerically
greater than other. |
boolean |
isGreaterThanOrEqualTo(Decimal<S> other)
Compares this
Decimal with the specified Decimal and returns true if this Decimal is numerically
greater than or equal to other. |
boolean |
isIntegral()
Returns true if this
Decimal number is integral, or equivalently if its fractional part is zero. |
boolean |
isIntegralPartZero()
Returns true if the
integral part of this Decimal number is zero. |
boolean |
isLessThan(Decimal<S> other)
Compares this
Decimal with the specified Decimal and returns true if this Decimal is numerically
less than other. |
boolean |
isLessThanOrEqualTo(Decimal<S> other)
Compares this
Decimal with the specified Decimal and returns true if this Decimal is numerically
less than or equal to other. |
boolean |
isMinusOne()
Returns true if this
Decimal is minus one. |
boolean |
isNegative()
Returns true if this
Decimal is negative. |
boolean |
isNonNegative()
Returns true if this
Decimal is not negative. |
boolean |
isNonPositive()
Returns true if this
Decimal is not positive. |
boolean |
isOne()
Returns true if this
Decimal is one. |
boolean |
isPositive()
Returns true if this
Decimal is strictly positive. |
boolean |
isUlp()
Returns true if this
Decimal is equal to the smallest positive number representable by a Decimal with the
current scale. |
boolean |
isZero()
Returns true if this
Decimal is zero. |
long |
longValue()
Converts this
Decimal to a long. |
long |
longValue(RoundingMode roundingMode)
Converts this
Decimal to a long using the specified rounding mode if necessary. |
long |
longValueExact()
Converts this
Decimal to a long, checking for lost information. |
Decimal<S> |
max(Decimal<S> val)
Returns the maximum of this
Decimal and val. |
Decimal<S> |
min(Decimal<S> val)
Returns the minimum of this
Decimal and val. |
Decimal<S> |
multiply(Decimal<S> multiplicand)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiply(Decimal<S> multiplicand,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiply(Decimal<S> multiplicand,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiply(double multiplicand)
Returns a
Decimal whose value is (this * multiplicand) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
multiply(double multiplicand,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * multiplicand) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
multiply(long multiplicand)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiply(long multiplicand,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiplyBy(Decimal<?> multiplicand)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiplyBy(Decimal<?> multiplicand,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiplyBy(Decimal<?> multiplicand,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiplyByPowerOfTen(int n)
Returns a
Decimal whose value is (this * 10n) . |
Decimal<S> |
multiplyByPowerOfTen(int n,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * 10n) . |
Decimal<S> |
multiplyByPowerOfTen(int n,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this * 10n) . |
Decimal<?> |
multiplyExact(Decimal<?> multiplicand)
Returns a
Decimal whose value is (this * multiplicand). |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand,
int scale)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale). |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand,
int scale,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale). |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand,
int scale,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale). |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. |
Decimal<S> |
multiplyUnscaled(long unscaledMultiplicand,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. |
Decimal<S> |
negate()
Returns a
Decimal whose value is (-this). |
Decimal<S> |
negate(OverflowMode overflowMode)
Returns a
Decimal whose value is (-this). |
Decimal<S> |
pow(int n)
Returns a
Decimal whose value is (thisn) using default HALF_UP rounding. |
Decimal<S> |
pow(int n,
RoundingMode roundingMode)
Returns a
Decimal whose value is (thisn) applying the specified roundingMode. |
Decimal<S> |
pow(int n,
TruncationPolicy truncationPolicy)
|
Decimal<S> |
remainder(Decimal<S> divisor)
Returns a
Decimal whose value is (this % divisor). |
Decimal<S> |
round(int precision)
|
Decimal<S> |
round(int precision,
RoundingMode roundingMode)
Returns a
Decimal value rounded to the specified precision using the given rounding mode. |
Decimal<S> |
round(int precision,
TruncationPolicy truncationPolicy)
Returns a
Decimal value rounded to the specified precision using the given truncation policy. |
Decimal<?> |
scale(int scale)
|
Decimal<?> |
scale(int scale,
RoundingMode roundingMode)
|
<S extends ScaleMetrics> |
scale(S scaleMetrics)
|
<S extends ScaleMetrics> |
scale(S scaleMetrics,
RoundingMode roundingMode)
|
Decimal<S> |
shiftLeft(int n)
Returns a
Decimal whose value is (this << n). |
Decimal<S> |
shiftLeft(int n,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this << n). |
Decimal<S> |
shiftLeft(int n,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this << n). |
Decimal<S> |
shiftRight(int n)
Returns a BigInteger whose value is
(this >> n). |
Decimal<S> |
shiftRight(int n,
RoundingMode roundingMode)
Returns a BigInteger whose value is
(this >> n). |
Decimal<S> |
shiftRight(int n,
TruncationPolicy truncationPolicy)
Returns a BigInteger whose value is
(this >> n). |
short |
shortValue()
Returns the value of this
Decimal as a short after a narrowing primitive conversion. |
short |
shortValueExact()
Converts this
Decimal to a short, checking for lost information. |
int |
signum()
Returns the signum function of this
Decimal. |
Decimal<S> |
sqrt()
Returns a
Decimal whose value is the square root of this Decimal value. |
Decimal<S> |
sqrt(RoundingMode roundingMode)
Returns a
Decimal whose value is the square root of this Decimal value. |
Decimal<S> |
square()
Returns a
Decimal whose value is (this2). |
Decimal<S> |
square(RoundingMode roundingMode)
Returns a
Decimal whose value is (this2). |
Decimal<S> |
square(TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this2). |
Decimal<S> |
subtract(Decimal<?> subtrahend,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this - subtrahend) after converting the given
subtrahend argument to the scale of this Decimal. |
Decimal<S> |
subtract(Decimal<?> subtrahend,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this - subtrahend) after converting the given
subtrahend argument to the scale of this Decimal. |
Decimal<S> |
subtract(Decimal<S> subtrahend)
Returns a
Decimal whose value is (this - subtrahend). |
Decimal<S> |
subtract(Decimal<S> subtrahend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this - subtrahend). |
Decimal<S> |
subtract(double subtrahend)
Returns a
Decimal whose value is (this - subtrahend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
subtract(double subtrahend,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this - subtrahend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. |
Decimal<S> |
subtract(long subtrahend)
Returns a
Decimal whose value is (this - subtrahend). |
Decimal<S> |
subtract(long subtrahend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this - subtrahend). |
Decimal<S> |
subtractSquared(Decimal<S> value)
Returns a
Decimal whose value is (this - value2). |
Decimal<S> |
subtractSquared(Decimal<S> value,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this - value2). |
Decimal<S> |
subtractSquared(Decimal<S> value,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this - value2). |
Decimal<S> |
subtractUnscaled(long unscaledSubtrahend)
Returns a
Decimal whose value is (this - unscaledSubtrahend × 10-scale) with
the scale of this Decimal. |
Decimal<S> |
subtractUnscaled(long unscaledSubtrahend,
int scale)
Returns a
Decimal whose value is (this - unscaledSubtrahend × 10-scale). |
Decimal<S> |
subtractUnscaled(long unscaledSubtrahend,
int scale,
RoundingMode roundingMode)
Returns a
Decimal whose value is (this - unscaledSubtrahend × 10-scale). |
Decimal<S> |
subtractUnscaled(long unscaledSubtrahend,
int scale,
TruncationPolicy truncationPolicy)
Returns a
Decimal whose value is (this - unscaledSubtrahend × 10-scale). |
Decimal<S> |
subtractUnscaled(long unscaledSubtrahend,
OverflowMode overflowMode)
Returns a
Decimal whose value is (this - unscaledSubtrahend × 10-scale) with
the scale of this Decimal. |
BigDecimal |
toBigDecimal()
|
BigDecimal |
toBigDecimal(int scale,
RoundingMode roundingMode)
Returns a
BigDecimal value of the given scale using the specified rounding mode if necessary. |
BigInteger |
toBigInteger()
Converts this
Decimal to a BigInteger. |
BigInteger |
toBigInteger(RoundingMode roundingMode)
Converts this
Decimal to a BigInteger value using the specified rounding mode if necessary. |
BigInteger |
toBigIntegerExact()
Converts this
Decimal to a BigInteger, checking for lost information. |
ImmutableDecimal<S> |
toImmutableDecimal()
If this
Decimal value is already an ImmutableDecimal it is simply returned. |
MutableDecimal<S> |
toMutableDecimal()
If this
Decimal value is already a MutableDecimal it is simply returned. |
String |
toString()
Returns a string representation of this
Decimal object as fixed-point Decimal always showing all Decimal
places (also trailing zeros) and a leading sign character if negative. |
long |
unscaledValue()
Returns the unscaled value underlying this
Decimal. |
S getScaleMetrics()
long value underlying this Decimal.ScaleMetrics.getScale(),
ScaleMetrics.getScaleFactor()int getScale()
long value underlying this Decimal.
If the scale is f then the value represented by a Decimal instance is
(unscaledValue × 10-f).
This method is a shortcut for getScaleMetrics().getScale().
getScaleMetrics(),
ScaleMetrics.getScale(),
unscaledValue()long unscaledValue()
Decimal. This Decimal is
(unscaledValue × 10-f) with f representing the scale, hence
the returned value equals (10f × this).getScale(),
ScaleMetrics.getScaleFactor()DecimalFactory<S> getFactory()
this Decimal.Decimal<S> integralPart()
Decimal whose value represents the integral part of this Decimal. The integral part
corresponds to digits at the left of the decimal point. The result is this Decimal rounded to precision
zero with RoundingMode.DOWN.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the operation.
⌊this⌋ for non-negative and ⌈this⌉ for negative
valuesfractionalPart(),
isIntegral(),
isIntegralPartZero(),
round(int, RoundingMode)Decimal<S> fractionalPart()
Decimal whose value represents the fractional part of (this) value. The fractional part
corresponds to digits at the right of the decimal point. The result is this minus the integral part of
this Decimal.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the operation.
this-integralPart() which is always less than one and greater than minus oneintegralPart(),
isIntegral(),
isIntegralPartZero()byte byteValue()
Decimal as a byte after a narrowing primitive conversion.Decimal converted to an byte.Number.byteValue(),
byteValueExact()byte byteValueExact()
Decimal to a byte, checking for lost information. If this Decimal has a
nonzero fractional part or is out of the possible range for a byte result then an
ArithmeticException is thrown.Decimal converted to a byte.ArithmeticException - if this has a nonzero fractional part, or will not fit in a byte.byteValue()short shortValue()
Decimal as a short after a narrowing primitive conversion.Decimal converted to an short.Number.shortValue(),
shortValueExact()short shortValueExact()
Decimal to a short, checking for lost information. If this Decimal has a
nonzero fractional part or is out of the possible range for a short result then an
ArithmeticException is thrown.Decimal converted to a short.ArithmeticException - if this has a nonzero fractional part, or will not fit in a short.shortValue()int intValue()
Decimal to an int. This conversion is analogous to the narrowing primitive
conversion from double to short as defined in section 5.1.3 of The Java™ Language
Specification: any fractional part of this Decimal will be discarded, and if the resulting
"long" is too big to fit in an int, only the low-order 32 bits are returned. Note that this
conversion can lose information about the overall magnitude and precision of this Decimal value as well
as return a result with the opposite sign.Decimal converted to an int.Number.intValue(),
intValueExact()int intValueExact()
Decimal to an int, checking for lost information. If this Decimal has a
nonzero fractional part or is out of the possible range for an int result then an
ArithmeticException is thrown.Decimal converted to an int.ArithmeticException - if this has a nonzero fractional part, or will not fit in an int.intValue()long longValue()
Decimal to a long. This conversion is analogous to the narrowing primitive
conversion from double to short as defined in section 5.1.3 of The Java™ Language
Specification: any fractional part of this Decimal will be discarded. Note that this conversion
can lose information about the precision of the Decimal value.
Note that this method uses RoundingMode.DOWN as defined by The Java™Language
Specification. Other rounding modes are supported via longValue(RoundingMode).
Decimal converted to a long.Number.longValue(),
longValue(RoundingMode),
longValueExact()long longValueExact()
Decimal to a long, checking for lost information. If this Decimal has a
nonzero fractional part or is out of the possible range for a long result then an
ArithmeticException is thrown.Decimal converted to a long.ArithmeticException - if this has a nonzero fractional partlongValue(),
longValue(RoundingMode)float floatValue()
Decimal to a float. This conversion is similar to the narrowing primitive
conversion from double to float as defined in section 5.1.3 of The Java™ Language
Specification. Note that this conversion can lose information about the precision of the Decimal
value.
Note that this method uses RoundingMode.HALF_EVEN as defined by The Java™Language
Specification. Other rounding modes are supported via floatValue(RoundingMode).
Decimal converted to a float.Number.floatValue(),
floatValue(RoundingMode)double doubleValue()
Decimal to a double. This conversion is similar to the narrowing primitive
conversion from double to float as defined in section 5.1.3 of The Java™ Language
Specification. Note that this conversion can lose information about the precision of the Decimal
value.
Note that this method uses RoundingMode.HALF_EVEN as defined by The Java™Language
Specification. Other rounding modes are supported via doubleValue(RoundingMode).
Decimal converted to a double.Number.doubleValue(),
doubleValue(RoundingMode)BigInteger toBigInteger()
Decimal to a BigInteger. This conversion is analogous to the narrowing primitive
conversion from double to long as defined in section 5.1.3 of The Java™ Language
Specification: any fractional part of this Decimal will be discarded. Note that this conversion
can lose information about the precision of the Decimal value.
To have an exception thrown if the conversion is inexact (in other words if a nonzero fractional part is
discarded), use the toBigIntegerExact() method.
Note that this method uses RoundingMode.DOWN to be consistent with other integer conversion methods as
defined by The Java™Language Specification. Other rounding modes are supported via
toBigInteger(RoundingMode).
Decimal converted to a BigInteger.toBigIntegerExact(),
toBigInteger(RoundingMode),
longValue()BigInteger toBigIntegerExact()
Decimal to a BigInteger, checking for lost information. An exception is thrown if
this Decimal has a nonzero fractional part.Decimal converted to a BigInteger.ArithmeticException - if this has a nonzero fractional part.toBigInteger(),
toBigInteger(RoundingMode),
longValueExact()BigDecimal toBigDecimal()
Decimal converted to a BigDecimal with the same scale as this Decimal value.toBigDecimal(int, RoundingMode)ImmutableDecimal<S> toImmutableDecimal()
Decimal value is already an ImmutableDecimal it is simply returned. Otherwise a new
immutable value with the same scale and numerical value as this Decimal is created and returned.this if immutable and a new ImmutableDecimal with the same scale and value as
this Decimal otherwiseMutableDecimal<S> toMutableDecimal()
Decimal value is already a MutableDecimal it is simply returned. Otherwise a new mutable
value with the same scale and numerical value as this Decimal is created and returned.this if mutable and a new MutableDecimal with the same scale and value as this
Decimal otherwiselong longValue(RoundingMode roundingMode)
Decimal to a long using the specified rounding mode if necessary. Rounding is
applied if the Decimal value can not be represented as a long value, that is, if it has a nonzero fractional
part. Note that this conversion can lose information about the precision of the Decimal value.roundingMode - the rounding mode to apply when rounding is necessary to convert this Decimal into a longDecimal converted to a long.ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessarylongValue(),
longValueExact()float floatValue(RoundingMode roundingMode)
Decimal to a float using the specified rounding mode if the Decimal value can not
be exactly represented as a float value. Note that this conversion can lose information about the precision of
the Decimal value.roundingMode - the rounding mode to apply when rounding is necessary to convert this Decimal into a float valueDecimal converted to a float.ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryfloatValue()double doubleValue(RoundingMode roundingMode)
Decimal to a double using the specified rounding mode if the Decimal value can not
be exactly represented as a double value. Note that this conversion can lose information about the precision of
the Decimal value.roundingMode - the rounding mode to apply when rounding is necessary to convert this Decimal into a double valueDecimal converted to a double.ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessarydoubleValue()BigInteger toBigInteger(RoundingMode roundingMode)
Decimal to a BigInteger value using the specified rounding mode if necessary.
Rounding is applied if the Decimal value can not be represented as a BigInteger, that is, if it has a
nonzero fractional part. Note that this conversion can lose information about the precision of the
Decimal value.roundingMode - the rounding mode to apply when rounding is necessary to convert this Decimal into a
BigIntegerDecimal converted to a BigInteger.ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessarytoBigInteger(),
toBigIntegerExact()BigDecimal toBigDecimal(int scale, RoundingMode roundingMode)
BigDecimal value of the given scale using the specified rounding mode if necessary.scale - the scale used for the returned BigDecimalroundingMode - the rounding mode to apply when rounding is necessary to convert from the this Decimal's
scale to the target scaleBigDecimal instance of the specified scaleArithmeticException - if roundingMode==UNNECESSARY and rounding is necessarytoBigDecimal()Decimal<S> round(int precision)
Decimal value rounded to the specified precision using HALF_UP rounding. If an overflow occurs due to the rounding operation, the result is silently truncated.
Note that contrary to the scale(..) operations this method does not change the scale of the value ---
extra digits are simply zeroised.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the rounded value.
Examples and special cases:
IllegalArgumentException is thrownprecision - the precision to use for the rounding, for instance 2 to round to the second digit after the decimal
point; must be at least (scale - 18)IllegalArgumentException - if precision < scale - 18round(int, RoundingMode),
round(int, TruncationPolicy),
scale(int)Decimal<S> round(int precision, RoundingMode roundingMode)
Decimal value rounded to the specified precision using the given rounding mode. If an
overflow occurs due to the rounding operation, the result is silently truncated.
Note that contrary to the scale(..) operations this method does not change the scale of the value ---
extra digits are simply zeroised.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the rounded value.
Examples and special cases:
IllegalArgumentException is thrownprecision - the precision to use for the rounding, for instance 2 to round to the second digit after the decimal
point; must be at least (scale - 18)roundingMode - the rounding mode to apply when rounding to the desired precisionIllegalArgumentException - if precision < scale - 18ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryround(int),
round(int, TruncationPolicy),
scale(int, RoundingMode)Decimal<S> round(int precision, TruncationPolicy truncationPolicy)
Decimal value rounded to the specified precision using the given truncation policy.
Note that contrary to the scale(..) operations this method does not change the scale of the value ---
extra digits are simply zeroised.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the rounded value.
Examples and special cases:
IllegalArgumentException is thrownprecision - the precision to use for the rounding, for instance 2 to round to the second digit after the decimal
point; must be at least (scale - 18)truncationPolicy - the truncation policy defining RoundingMode and OverflowMode for the rounding
operationIllegalArgumentException - if precision < scale - 18ArithmeticException - if truncationPolicy specifies RoundingMode.UNNECESSARY and rounding is necessary or
if an overflow occurs and the policy declares OverflowMode.CHECKEDround(int),
round(int, RoundingMode),
scale(int, RoundingMode)Decimal<?> scale(int scale)
Decimal value whose scale is changed to the given scale value.
HALF_UP rounding is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale - the scale to use for the result, must be in [0,18]IllegalArgumentException - if scale < 0 or scale > 18ArithmeticException - if an overflow occurs during the scale conversionscale(ScaleMetrics),
scale(int, RoundingMode),
round(int)<S extends ScaleMetrics> Decimal<S> scale(S scaleMetrics)
Decimal value whose scale is changed to the scale given by the
scaleMetrics argument. HALF_UP rounding is used if the scale change involves
rounding.
An exception is thrown if the scale conversion leads to an overflow.
S - the scale metrics type of the resultscaleMetrics - the scale metrics to use for the resultArithmeticException - if an overflow occurs during the scale conversionscale(int),
scale(ScaleMetrics, RoundingMode),
round(int)Decimal<?> scale(int scale, RoundingMode roundingMode)
Decimal value whose scale is changed to the given scale value. The
specified roundingMode is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale - the scale to use for the result, must be in [0,18]roundingMode - the rounding mode to apply if the scale change involves roundingIllegalArgumentException - if scale < 0 or scale > 18ArithmeticException - if roundingMode is UNNESSESSARY and rounding is necessary,
or if an overflow occurs during the scale conversionscale(int),
scale(ScaleMetrics, RoundingMode),
round(int, RoundingMode)<S extends ScaleMetrics> Decimal<S> scale(S scaleMetrics, RoundingMode roundingMode)
Decimal value whose scale is changed to the scale given by the
scaleMetrics argument. The specified roundingMode is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
S - the scale metrics type of the resultscaleMetrics - the scale metrics to use for the resultroundingMode - the rounding mode to apply if the scale change involves roundingArithmeticException - if roundingMode is UNNESSESSARY and rounding is necessary,
or if an overflow occurs during the scale conversionscale(ScaleMetrics),
scale(int, RoundingMode),
round(int, RoundingMode)Decimal<S> add(Decimal<S> augend)
Decimal whose value is (this + augend). If the addition causes an overflow, the result
is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this Decimalthis + augendDecimal<S> add(Decimal<S> augend, OverflowMode overflowMode)
Decimal whose value is (this + augend). The specified overflowMode determines
whether to truncate the result silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this DecimaloverflowMode - the overflow mode to apply if the addition leads to an overflowthis + augendArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> add(Decimal<?> augend, RoundingMode roundingMode)
Decimal whose value is (this + augend). The result of the addition is rounded if
necessary using the specified roundingMode. Overflows during scale conversion or subtraction are silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this DecimalroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> add(Decimal<?> augend, TruncationPolicy truncationPolicy)
Decimal whose value is (this + augend). The result of the addition is rounded if
necessary using the RoundingMode defined by the truncationPolicy argument. The
truncationPolicy also defines the OverflowMode to apply if the operation causes an overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occurs during the additionround(this + augend)ArithmeticException - if truncationPolicy specifies RoundingMode.UNNECESSARY and rounding is necessary or
if an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> add(long augend)
Decimal whose value is (this + augend) after converting the given long value to
the scale of this Decimal. If the operation causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - long value to be added to this Decimalthis + augendDecimal<S> add(long augend, OverflowMode overflowMode)
Decimal whose value is (this + augend) after converting the given long value to
the scale of this Decimal. The specified overflowMode determines whether to truncate the result
silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - long value to be added to this DecimaloverflowMode - the overflow mode to apply if the addition leads to an overflowthis + augendArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> add(double augend)
Decimal whose value is (this + augend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. If rounding is necessary,
HALF_UP rounding mode is used and applied during the conversion step before
the addition operation. Overflows due to conversion or addition result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this DecimalIllegalArgumentException - if augend is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if an overflow occurs during the addition operationDecimal<S> add(double augend, RoundingMode roundingMode)
Decimal whose value is (this + augend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. If rounding is necessary, the specified
roundingMode is used and applied during the conversion step before the addition operation.
Overflows due to conversion or addition result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
augend - value to be added to this DecimalroundingMode - the rounding mode to apply if the augend argument needs to be rounded when converted into a Decimal
number of the same scale as this Decimalthis + round(augend)IllegalArgumentException - if augend is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if roundingMode==UNNECESSARY and rounding is necessary or if an overflow occurs during the
addition operationDecimal<S> addUnscaled(long unscaledAugend)
Decimal whose value is (this + unscaledAugend × 10-scale) with the
scale of this Decimal. If the addition causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
unscaledAugend - value to be added to this DecimalDecimal<S> addUnscaled(long unscaledAugend, OverflowMode overflowMode)
Decimal whose value is (this + unscaledAugend × 10-scale) with the
scale of this Decimal. The specified overflowMode determines whether to truncate the
result silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
unscaledAugend - value to be added to this DecimaloverflowMode - the overflow mode to apply if the addition leads to an overflowArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> addUnscaled(long unscaledAugend, int scale)
Decimal whose value is (this + unscaledAugend × 10-scale). The result
of the addition is rounded if necessary using HALF_UP rounding. If the operation
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
unscaledAugend - value to be added to this Decimalscale - the scale to apply to unscaledAugend, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tenDecimal<S> addUnscaled(long unscaledAugend, int scale, RoundingMode roundingMode)
Decimal whose value is (this + unscaledAugend × 10-scale). The result
of the addition is rounded if necessary using the specified roundingMode. If the operation causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
unscaledAugend - value to be added to this Decimalscale - the scale to apply to unscaledAugend, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tenroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> addUnscaled(long unscaledAugend, int scale, TruncationPolicy truncationPolicy)
Decimal whose value is (this + unscaledAugend × 10-scale). The result
of the addition is rounded if necessary using the RoundingMode defined by the truncationPolicy
argument. The truncationPolicy also defines the OverflowMode to apply if the operation causes an
overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
unscaledAugend - value to be added to this Decimalscale - the scale to apply to unscaledAugend, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tentruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occurs during the additionArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> addSquared(Decimal<S> value)
Decimal whose value is (this + value2). The squared value is rounded
before the addition if necessary using default HALF_UP rounding. Overflows
during squaring or addition are silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
value - value to be squared and added to this DecimalDecimal<S> addSquared(Decimal<S> value, RoundingMode roundingMode)
Decimal whose value is (this + value2). The squared value is rounded
before the addition if necessary using the specified roundingMode. Overflows during squaring or
addition are silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
value - value to be squared and added to this DecimalroundingMode - the rounding mode to apply if necessary when squaring the valueArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> addSquared(Decimal<S> value, TruncationPolicy truncationPolicy)
Decimal whose value is (this + value2). The squared value is rounded
before the addition if necessary using the RoundingMode specified by the truncationPolicy
argument. The truncationPolicy also defines the OverflowMode to apply if an overflow occurs
during square or add operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the addition.
value - value to be squared and added to this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary when squaring the value or if an overflow occurs during the square or add operationArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> subtract(Decimal<S> subtrahend)
Decimal whose value is (this - subtrahend). If the subtraction causes an overflow, the
result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this Decimalthis - subtrahendDecimal<S> subtract(Decimal<S> subtrahend, OverflowMode overflowMode)
Decimal whose value is (this - subtrahend). The specified overflowMode
determines whether to truncate the result silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this DecimaloverflowMode - the overflow mode to apply if the subtraction leads to an overflowthis - subtrahendArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> subtract(Decimal<?> subtrahend, RoundingMode roundingMode)
Decimal whose value is (this - subtrahend) after converting the given
subtrahend argument to the scale of this Decimal. The result of the subtraction is rounded if
necessary using the specified roundingMode. Overflows during scale conversion or subtraction are silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this DecimalroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> subtract(Decimal<?> subtrahend, TruncationPolicy truncationPolicy)
Decimal whose value is (this - subtrahend) after converting the given
subtrahend argument to the scale of this Decimal. The result of the subtraction is rounded if
necessary using the RoundingMode defined by the truncationPolicy argument. The
truncationPolicy also defines the OverflowMode to apply if the operation causes an overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occurs during the subtractionArithmeticException - if truncationPolicy specifies RoundingMode.UNNECESSARY and rounding is necessary or
if an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> subtract(long subtrahend)
Decimal whose value is (this - subtrahend). If the subtraction causes an overflow, the
result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - long value to be subtracted from this Decimalthis - subtrahendDecimal<S> subtract(long subtrahend, OverflowMode overflowMode)
Decimal whose value is (this - subtrahend). The specified overflowMode
determines whether to truncate the result silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - long value to be subtracted from this DecimaloverflowMode - the overflow mode to apply if the subtraction leads to an overflowthis - subtrahendArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> subtract(double subtrahend)
Decimal whose value is (this - subtrahend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. If rounding is necessary,
HALF_UP rounding mode is used and applied during the conversion step before
the subtraction operation. Overflows due to conversion or subtraction result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this DecimalIllegalArgumentException - if subtrahend is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if an overflow occurs during the subtraction operationDecimal<S> subtract(double subtrahend, RoundingMode roundingMode)
Decimal whose value is (this - subtrahend) after converting the given double
argument into a Decimal value of the same scale as this Decimal. If rounding is necessary, the specified
roundingMode is used and applied during the conversion step before the subtraction operation.
Overflows due to conversion or subtraction result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
subtrahend - value to be subtracted from this DecimalroundingMode - the rounding mode to apply if the subtrahend argument needs to be rounded when converted into a
Decimal number of the same scale as this DecimalIllegalArgumentException - if subtrahend is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if roundingMode==UNNECESSARY and rounding is necessary or if an overflow occurs during the
subtraction operationDecimal<S> subtractUnscaled(long unscaledSubtrahend)
Decimal whose value is (this - unscaledSubtrahend × 10-scale) with
the scale of this Decimal. If the subtraction causes an overflow, the result is silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
unscaledSubtrahend - value to be subtracted from this DecimalDecimal<S> subtractUnscaled(long unscaledSubtrahend, OverflowMode overflowMode)
Decimal whose value is (this - unscaledSubtrahend × 10-scale) with
the scale of this Decimal. The specified overflowMode determines whether to truncate
the result silently or to throw an exception if an overflow occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
unscaledSubtrahend - value to be subtracted from this DecimaloverflowMode - the overflow mode to apply if the subtraction leads to an overflowArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> subtractUnscaled(long unscaledSubtrahend, int scale)
Decimal whose value is (this - unscaledSubtrahend × 10-scale). The
result of the subtraction is rounded if necessary using HALF_UP rounding. If the
operation causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
unscaledSubtrahend - value to be subtracted from this Decimalscale - the scale to apply to unscaledSubtrahend, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tenDecimal<S> subtractUnscaled(long unscaledSubtrahend, int scale, RoundingMode roundingMode)
Decimal whose value is (this - unscaledSubtrahend × 10-scale). The
result of the subtraction is rounded if necessary using the specified roundingMode. If the operation
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
unscaledSubtrahend - value to be subtracted from this Decimalscale - the scale to apply to unscaledSubtrahend, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tenroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> subtractUnscaled(long unscaledSubtrahend, int scale, TruncationPolicy truncationPolicy)
Decimal whose value is (this - unscaledSubtrahend × 10-scale). The
result of the subtraction is rounded if necessary using the RoundingMode defined by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
the operation causes an overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
unscaledSubtrahend - value to be subtracted from this Decimalscale - the scale to apply to unscaledSubtrahend, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tentruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occurs during the subtractionArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> subtractSquared(Decimal<S> value)
Decimal whose value is (this - value2). The squared value is rounded
before the subtraction if necessary using default HALF_UP rounding. Overflows
during squaring or subtraction are silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
value - value to be squared and subtracted from this DecimalDecimal<S> subtractSquared(Decimal<S> value, RoundingMode roundingMode)
Decimal whose value is (this - value2). The squared value is rounded
before the subtraction if necessary using the specified roundingMode. Overflows during squaring or
subtraction are silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
value - value to be squared and subtracted from this DecimalroundingMode - the rounding mode to apply if necessary when squaring the valueArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> subtractSquared(Decimal<S> value, TruncationPolicy truncationPolicy)
Decimal whose value is (this - value2). The squared value is rounded
before the subtraction if necessary using the RoundingMode specified by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
an overflow occurs during square or subtract operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the subtraction.
value - value to be squared and subtracted from this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary when squaring the value or if an overflow occurs during the square or subtract operationArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> multiply(Decimal<S> multiplicand)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using default HALF_UP rounding. If the
multiplication causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalDecimal<S> multiply(Decimal<S> multiplicand, RoundingMode roundingMode)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the multiplication causes
an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalroundingMode - the rounding mode to apply if the result needs to be roundedArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> multiply(Decimal<S> multiplicand, TruncationPolicy truncationPolicy)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using the RoundingMode specified by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
an overflow occurs during the multiply operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> multiplyBy(Decimal<?> multiplicand)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using HALF_UP rounding. If the
multiplication causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalDecimal<S> multiplyBy(Decimal<?> multiplicand, RoundingMode roundingMode)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the multiplication causes
an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> multiplyBy(Decimal<?> multiplicand, TruncationPolicy truncationPolicy)
Decimal whose value is (this * multiplicand). The result is rounded to the
scale of this Decimal using the RoundingMode defined by the truncationPolicy
argument. The truncationPolicy also defines the OverflowMode to apply if the operation causes an
overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<?> multiplyExact(Decimal<?> multiplicand)
Decimal whose value is (this * multiplicand). The scale of the returned value is the
sum of the scales of this Decimal and the multiplicand argument. If the result scale exceeds 18,
an IllegalArgumentException is thrown. An ArithmeticException is thrown if the product is out of
the possible range for a Decimal with the result scale.
Note that the result is always a new instance --- immutable if this Decimal is an ImmutableDecimal
and mutable if it is a MutableDecimal.
multiplicand - factor to multiply with this Decimal(this * multiplicand) with scale equal to the sum of scales of this and
multiplicandIllegalArgumentException - if the sum of the scales of this Decimal and the multiplicand argument exceeds 18ArithmeticException - if an overflow occurs and product is out of the possible range for a Decimal with the result scaleDecimal<S> multiply(long multiplicand)
Decimal whose value is (this * multiplicand). If the multiplication causes an overflow,
the result is silently truncated.
This method performs multiplication of this Decimal with a long value which is usually more
efficient than multiplication of two Decimal values.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this Decimal(this * multiplicand)Decimal<S> multiply(long multiplicand, OverflowMode overflowMode)
Decimal whose value is (this * multiplicand). The specified overflowMode
determines whether to truncate the result silently or to throw an exception if an overflow occurs.
This method performs multiplication of this Decimal with a long value which is usually more
efficient than multiplication of two Decimal values.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimaloverflowMode - the overflow mode to apply if the multiplication leads to an overflow(this * multiplicand)ArithmeticException - if overflowMode==CHECKED and an overflow occursDecimal<S> multiply(double multiplicand)
Decimal whose value is (this * multiplicand) after converting the given double
argument into a Decimal value of the same scale as this Decimal. HALF_UP
rounding mode is used if necessary and applied twice during the conversion step before the multiplication
and again when rounding the product to the scale of this Decimal. Overflows due to conversion
or multiplication result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalIllegalArgumentException - if multiplicand is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if an overflow occurs during the multiply operationDecimal<S> multiply(double multiplicand, RoundingMode roundingMode)
Decimal whose value is (this * multiplicand) after converting the given double
argument into a Decimal value of the same scale as this Decimal. Rounding, if necessary, uses the
specified roundingMode and is applied during the conversion step before the multiplication and
again when rounding the product to the scale of this Decimal. Overflows due to conversion or
multiplication result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
multiplicand - factor to multiply with this DecimalroundingMode - the rounding mode to apply if the converted multiplicand or the resulting product needs to be roundedround(this * round(multiplicand))IllegalArgumentException - if multiplicand is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if roundingMode==UNNECESSARY and rounding is necessary or if an overflow occurs during the
multiply operationDecimal<S> multiplyUnscaled(long unscaledMultiplicand)
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. The result is rounded to the scale of this Decimal using default
HALF_UP rounding. If the multiplication causes an overflow, the result is silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this DecimalDecimal<S> multiplyUnscaled(long unscaledMultiplicand, RoundingMode roundingMode)
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. The result is rounded to the scale of this Decimal using the
specified roundingMode. If the multiplication causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this DecimalroundingMode - the rounding mode to apply if the result needs to be roundedArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> multiplyUnscaled(long unscaledMultiplicand, TruncationPolicy truncationPolicy)
Decimal whose value is (this * unscaledMultiplicand × 10-scale) with
the scale of this Decimal. The result is rounded to the scale of this Decimal using the using
the RoundingMode specified by the truncationPolicy argument. The truncationPolicy also
defines the OverflowMode to apply if an overflow occurs during the multiplication.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this DecimaltruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> multiplyUnscaled(long unscaledMultiplicand, int scale)
Decimal whose value is (this * unscaledMultiplicand × 10-scale). The
result of the multiplication is rounded to the scale of this Decimal using
HALF_UP rounding. If the operation causes an overflow, the result is silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this Decimalscale - the scale to apply to unscaledMultiplicand, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tenDecimal<S> multiplyUnscaled(long unscaledMultiplicand, int scale, RoundingMode roundingMode)
Decimal whose value is (this * unscaledMultiplicand × 10-scale). The
result of the multiplication is rounded to the scale of this Decimal using the specified
roundingMode. If the operation causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this Decimalscale - the scale to apply to unscaledMultiplicand, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tenroundingMode - the rounding mode to apply if rounding is necessaryArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> multiplyUnscaled(long unscaledMultiplicand, int scale, TruncationPolicy truncationPolicy)
Decimal whose value is (this * unscaledMultiplicand × 10-scale). The
result of the multiplication is rounded to the scale of this Decimal using the
RoundingMode defined by the truncationPolicy argument. The truncationPolicy also defines
the OverflowMode to apply if the operation causes an overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
unscaledMultiplicand - factor to multiply with this Decimalscale - the scale to apply to unscaledMultiplicand, positive to indicate the number of fraction digits
to the right of the Decimal point and negative to indicate up-scaling with a power of tentruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> multiplyByPowerOfTen(int n)
Decimal whose value is (this * 10n) . For negative n the
multiplication turns into a de-facto division and the result is rounded to the scale of this
Decimal using default HALF_UP rounding. If the multiplication causes an overflow,
the result is silently truncated.
The result of this operation is the same as for divideByPowerOfTen(-n) given
n > Integer.MIN_VALUE.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
n - the exponent of the power-of-ten factor to multiply with this DecimalDecimal<S> multiplyByPowerOfTen(int n, RoundingMode roundingMode)
Decimal whose value is (this * 10n) . For negative n the
multiplication turns into a de-facto division and the result is rounded to the scale of this
Decimal using the specified roundingMode. If the multiplication causes an overflow, the result is
silently truncated.
The result of this operation is the same as for divideByPowerOfTen(-n, roundingMode) given n > Integer.MIN_VALUE.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
n - the exponent of the power-of-ten factor to multiply with this DecimalroundingMode - the rounding mode to apply if the result needs to be rounded for the case n < 0ArithmeticException - if n < 0 and roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> multiplyByPowerOfTen(int n, TruncationPolicy truncationPolicy)
Decimal whose value is (this * 10n) . For negative n the
multiplication turns into a de-facto division and the result is rounded to the scale of this
Decimal using the RoundingMode specified by the truncationPolicy argument. The
truncationPolicy also defines the OverflowMode to apply if an overflow occurs during the
multiplication.
The result of this operation is the same as for divideByPowerOfTen(-n, truncationPolicy) given n > Integer.MIN_VALUE.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the multiplication.
n - the exponent of the power-of-ten factor to multiply with this DecimaltruncationPolicy - the truncation policy specifying RoundingMode to apply if rounding is necessary when
n < 0 as well OverflowMode to use if n > 0 and an overflow occurs during the
multiplicationArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary when
n < 0, or if an overflow occurs and the policy declares OverflowMode.CHECKED for the
case n > 0Decimal<S> divide(Decimal<S> divisor)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using HALF_UP rounding. If the division
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedArithmeticException - if divisor==0Decimal<S> divide(Decimal<S> divisor, RoundingMode roundingMode)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the division causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedroundingMode - the rounding mode to apply if the result needs to be roundedround(this / divisor)ArithmeticException - if divisor==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divide(Decimal<S> divisor, TruncationPolicy truncationPolicy)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the RoundingMode specified by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
an overflow occurs during the divide operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedtruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if divisor==0, or if truncationPolicy defines RoundingMode.UNNECESSARY and
rounding is necessary or if an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> divideBy(Decimal<?> divisor)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using HALF_UP rounding. If the division
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedArithmeticException - if divisor==0Decimal<S> divideBy(Decimal<?> divisor, RoundingMode roundingMode)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the division causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedroundingMode - the rounding mode to apply if rounding is necessaryround(this / divisor)ArithmeticException - if divisor==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divideBy(Decimal<?> divisor, TruncationPolicy truncationPolicy)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the RoundingMode defined by the truncationPolicy
argument. The truncationPolicy also defines the OverflowMode to apply if the operation causes an
overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedtruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursround(this / divisor)ArithmeticException - if divisor==0, or if truncationPolicy defines RoundingMode.UNNECESSARY and
rounding is necessary, or if an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> divideTruncate(Decimal<S> divisor)
Decimal whose value is (this / divisor) rounded down. This method is a shortcut for
calling divide(divisor, RoundingMode.DOWN). If the division causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedArithmeticException - if divisor==0Decimal<S> divideExact(Decimal<S> divisor)
Decimal whose value is (this / divisor), checking for lost information. If the quotient
cannot be represented exactly with the scale of this Decimal then an
ArithmeticException is thrown.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedthis / divisorArithmeticException - if divisor==0, or if the result does not fit in a Decimal with the scale of this Decimal
without rounding and without exceeding the the possible range of such a DecimalDecimal<S> divide(long divisor)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using HALF_UP rounding. If the division
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - long value by which this Decimal is to be dividedArithmeticException - if divisor==0Decimal<S> divide(long divisor, RoundingMode roundingMode)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the division causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - long value by which this Decimal is to be dividedroundingMode - the rounding mode to apply if the result needs to be roundedround(this / divisor)ArithmeticException - if divisor==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divide(long divisor, TruncationPolicy truncationPolicy)
Decimal whose value is (this / divisor). The result is rounded to the
scale of this Decimal using the RoundingMode specified by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
an overflow occurs during the divide operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - long value by which this Decimal is to be dividedtruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if divisor==0, or if truncationPolicy defines RoundingMode.UNNECESSARY and
rounding is necessary, or if the policy declares OverflowMode.CHECKED an overflow occursDecimal<S> divide(double divisor)
Decimal whose value is (this / divisor) after converting the given double
argument into a Decimal value of the same scale as this Decimal. HALF_UP
rounding mode is used if necessary and applied twice during the conversion step before the division and
again when rounding the quotient to the scale of this Decimal. Overflows due to conversion or
division result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedIllegalArgumentException - if divisor is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if divisor==0 or if an overflow occurs during the divide operationDecimal<S> divide(double divisor, RoundingMode roundingMode)
Decimal whose value is (this / divisor) after converting the given double
argument into a Decimal value of the same scale as this Decimal. Rounding, if necessary, uses the
specified roundingMode and is applied during the conversion step before the division and again
when rounding the quotient to the scale of this Decimal. Overflows due to conversion or
division result in an exception.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - divisor value by which this Decimal is to be dividedroundingMode - the rounding mode to apply if the converted divisor or the resulting quotient needs to be roundedround(this / round(divisor))IllegalArgumentException - if divisor is NaN or infinite or if the magnitude is too large for the double to be
represented as a DecimalArithmeticException - if divisor==0, if roundingMode==UNNECESSARY and rounding is necessary or if an
overflow occurs during the divide operationDecimal<S> divideUnscaled(long unscaledDivisor)
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. The result is rounded to the scale of this Decimal using default
HALF_UP rounding. If the division causes an overflow, the result is silently
truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedArithmeticException - if unscaledDivisor==0Decimal<S> divideUnscaled(long unscaledDivisor, RoundingMode roundingMode)
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. The result is rounded to the scale of this Decimal using the specified
roundingMode. If the division causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedroundingMode - the rounding mode to apply if the result needs to be roundedArithmeticException - if unscaledDivisor==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divideUnscaled(long unscaledDivisor, TruncationPolicy truncationPolicy)
Decimal whose value is (this / (unscaledDivisor × 10-scale)) with the
scale of this Decimal. The result is rounded to the scale of this Decimal using the using the
RoundingMode specified by the truncationPolicy argument. The truncationPolicy also
defines the OverflowMode to apply if an overflow occurs during the division.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedtruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if unscaledDivisor==0, if truncationPolicy defines RoundingMode.UNNECESSARY
and rounding is necessary or if an overflow occurs and the policy declares
OverflowMode.CHECKEDDecimal<S> divideUnscaled(long unscaledDivisor, int scale)
Decimal whose value is (this / (unscaledDivisor × 10-scale)). The
result is rounded to the scale of this Decimal using HALF_UP rounding. If the
operation causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedscale - the scale to apply to unscaledDivisor, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tenArithmeticException - if unscaledDivisor==0Decimal<S> divideUnscaled(long unscaledDivisor, int scale, RoundingMode roundingMode)
Decimal whose value is (this / (unscaledDivisor × 10-scale)). The
result is rounded to the scale of this Decimal using the specified roundingMode. If the operation causes
an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedscale - the scale to apply to unscaledDivisor, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tenroundingMode - the rounding mode to apply if the result needs to be roundedArithmeticException - if unscaledDivisor==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divideUnscaled(long unscaledDivisor, int scale, TruncationPolicy truncationPolicy)
Decimal whose value is (this / (unscaledDivisor × 10-scale)). The
result is rounded to the scale of this Decimal using the RoundingMode defined by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
the operation causes an overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
unscaledDivisor - divisor value by which this Decimal is to be dividedscale - the scale to apply to unscaledDivisor, positive to indicate the number of fraction digits to
the right of the Decimal point and negative to indicate up-scaling with a power of tentruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursArithmeticException - if unscaledDivisor==0, if truncationPolicy defines RoundingMode.UNNECESSARY
and rounding is necessary or if an overflow occurs and the policy declares
OverflowMode.CHECKEDDecimal<S> divideByPowerOfTen(int n)
Decimal whose value is (this / 10n) . The result is rounded to the
scale of this Decimal using HALF_UP rounding.
For negative n the division turns into a de-facto multiplication. If the multiplication causes an overflow, the result is silently truncated.
The result of this operation is the same as for multiplyByPowerOfTen(-n)
(unless n == Integer.MIN_VALUE).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
n - the exponent of the power-of-ten divisor by which this Decimal is to be dividedDecimal<S> divideByPowerOfTen(int n, RoundingMode roundingMode)
Decimal whose value is (this / 10n) . The result is rounded to the
scale of this Decimal using the specified roudningMode.
For negative n the division turns into a de-facto multiplication. If the multiplication causes an overflow, the result is silently truncated.
The result of this operation is the same as for multiplyByPowerOfTen(-n, roundingMode) (unless n == Integer.MIN_VALUE).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
n - the exponent of the power-of-ten divisor by which this Decimal is to be dividedroundingMode - the rounding mode to apply if the result needs to be rounded for the case n > 0ArithmeticException - if n > 0 and roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> divideByPowerOfTen(int n, TruncationPolicy truncationPolicy)
Decimal whose value is (this / 10n) . The result is rounded to the
scale of this Decimal using the RoundingMode specified by the
truncationPolicy argument.
For negative n the division turns into a de-facto multiplication and truncationPolicy defines
the OverflowMode to apply if an overflow occurs during the multiplication.
The result of this operation is the same as for multiplyByPowerOfTen(-n, truncationPolicy) (unless n == Integer.MIN_VALUE).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
n - the exponent of the power-of-ten divisor by which this Decimal is to be dividedtruncationPolicy - the truncation policy specifying RoundingMode to apply if rounding is necessary when
n > 0 as well OverflowMode to use if n < 0 and an overflow occurs during the
de-facto multiplicationArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary when
n > 0, or if an overflow occurs and the policy declares OverflowMode.CHECKED for the
case n < 0Decimal<S> divideToIntegralValue(Decimal<S> divisor)
Decimal whose value is (this / divisor) rounded down to the next integer. If the
division causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - value by which this Decimal is to be divided.(this / divisor).ArithmeticException - if divisor==0divideToIntegralValue(Decimal, OverflowMode),
divideToLongValue(Decimal),
remainder(Decimal)Decimal<S> divideToIntegralValue(Decimal<S> divisor, OverflowMode overflowMode)
Decimal whose value is (this / divisor) rounded down to the next integer. The specified
overflowMode determines whether to truncate the result silently or to throw an exception if an overflow
occurs.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
divisor - value by which this Decimal is to be divided.overflowMode - the overflow mode to apply if the division leads to an overflow(this / divisor).ArithmeticException - if divisor==0 or if overflowMode==CHECKED and an overflow occursdivideToIntegralValue(Decimal),
divideToLongValue(Decimal),
remainder(Decimal)long divideToLongValue(Decimal<S> divisor)
Decimal whose value (this / divisor) rounded down to the next long value. If
the division causes an overflow, the result is silently truncated.divisor - value by which this Decimal is to be divided.(this / divisor) returned as longArithmeticException - if divisor==0divideToLongValue(Decimal, OverflowMode),
divideToIntegralValue(Decimal),
remainder(Decimal)long divideToLongValue(Decimal<S> divisor, OverflowMode overflowMode)
Decimal whose value (this / divisor) rounded down to the next long value. The
specified overflowMode determines whether to truncate the result silently or to throw an exception if an
overflow occurs.divisor - value by which this Decimal is to be divided.overflowMode - the overflow mode to apply if the division leads to an overflow(this / divisor) returned as longArithmeticException - if divisor==0 or if overflowMode==CHECKED and an overflow occursdivideToLongValue(Decimal),
divideToIntegralValue(Decimal),
remainder(Decimal)Decimal<S>[] divideAndRemainder(Decimal<S> divisor)
Decimal array containing the result of divideToIntegralValue followed by
the result of remainder on the two operands. If the division causes an overflow, the result is silently
truncated.
Note that if both the integer quotient and remainder are needed, this method is faster than using the
divideToIntegralValue and remainder methods separately because the division need only be carried
out once.
divisor - value by which this Decimal is to be divided, and the remainder computed.Decimal array: the quotient (the result of divideToIntegralValue) is the
initial element and the remainder is the final element.ArithmeticException - if divisor==0divideAndRemainder(Decimal, OverflowMode),
divideToIntegralValue(Decimal),
remainder(Decimal)Decimal<S>[] divideAndRemainder(Decimal<S> divisor, OverflowMode overflowMode)
Decimal array containing the result of divideToIntegralValue followed by
the result of remainder on the two operands. The specified overflowMode determines whether to
truncate the result silently or to throw an exception if an overflow occurs.
Note that if both the integer quotient and remainder are needed, this method is faster than using the
divideToIntegralValue and remainder methods separately because the division need only be carried
out once.
divisor - value by which this Decimal is to be divided, and the remainder computed.overflowMode - the overflow mode to apply if the division leads to an overflowDecimal array: the quotient (the result of divideToIntegralValue) is the
initial element and the remainder is the final element.ArithmeticException - if divisor==0 or if overflowMode==CHECKED and an overflow occursdivideAndRemainder(Decimal),
divideToIntegralValue(Decimal),
remainder(Decimal)Decimal<S> remainder(Decimal<S> divisor)
Decimal whose value is (this % divisor).
The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) . Note
that this is not the modulo operation (the result can be negative).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the operation.
divisor - value by which this Decimal is to be divided.this % divisor.ArithmeticException - if divisor==0divideToIntegralValue(Decimal),
divideAndRemainder(Decimal)Decimal<S> negate()
Decimal whose value is (-this).
If an overflow occurs (which is true iff this.unscaledValue()==Long.MIN_VALUE) then the result is still
negative and numerically equal to this value.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
-thisDecimal<S> negate(OverflowMode overflowMode)
Decimal whose value is (-this).
The specified overflowMode determines whether to truncate the result silently or to throw an exception if
an overflow occurs (which is true iff this.unscaledValue()==Long.MIN_VALUE).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
overflowMode - the overflow mode to apply-thisArithmeticException - if overflowMode==CHECKED and an overflow occurs (which is true iff
this.unscaledValue()==Long.MIN_VALUE)Decimal<S> abs()
Decimal whose value is the absolute value of this Decimal.
If an overflow occurs (which is true iff this.unscaledValue()==Long.MIN_VALUE) then the result is still
negative and numerically equal to this value.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
abs(this)Decimal<S> abs(OverflowMode overflowMode)
Decimal whose value is the absolute value of this Decimal.
The specified overflowMode determines whether to truncate the result silently or to throw an exception if
an overflow occurs (which is true iff this.unscaledValue()==Long.MIN_VALUE).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the division.
overflowMode - the overflow mode to applyabs(this)ArithmeticException - if overflowMode==CHECKED and an overflow occurs (which is true iff
this.unscaledValue()==Long.MIN_VALUE)Decimal<S> invert()
Decimal whose value is (1 / this). The result is rounded to the scale of this Decimal using default HALF_UP rounding. If the inversion causes an
overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the inversion.
ArithmeticException - if this==0Decimal<S> invert(RoundingMode roundingMode)
Decimal whose value is (1 / this). The result is rounded to the scale of this Decimal using the specified roundingMode. If the inversion causes an overflow, the result
is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the inversion.
roundingMode - the rounding mode to apply if the result needs to be roundedround(1 / this)ArithmeticException - if this==0 or if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> invert(TruncationPolicy truncationPolicy)
Decimal whose value is (1 / this). The result is rounded to the scale of this Decimal using the RoundingMode specified by the truncationPolicy argument. The
truncationPolicy also defines the OverflowMode to apply if an overflow occurs during the invert
operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the inversion.
truncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursround(1 / this)ArithmeticException - if this==0, if truncationPolicy defines RoundingMode.UNNECESSARY and rounding
is necessary or if an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> square()
Decimal whose value is (this2). The result is rounded to the
scale of this Decimal using default HALF_UP rounding. If the
square operation causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the square operation.
Decimal<S> square(RoundingMode roundingMode)
Decimal whose value is (this2). The result is rounded to the
scale of this Decimal using the specified roundingMode. If the square operation
causes an overflow, the result is silently truncated.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the square operation.
roundingMode - the rounding mode to apply if the result needs to be roundedround(this * this)ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryDecimal<S> square(TruncationPolicy truncationPolicy)
Decimal whose value is (this2). The result is rounded to the
scale of this Decimal using the RoundingMode specified by the
truncationPolicy argument. The truncationPolicy also defines the OverflowMode to apply if
an overflow occurs during the square operation.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the square operation.
truncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursround(this * this)ArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDDecimal<S> sqrt()
Decimal whose value is the square root of this Decimal value. The result is rounded to
the scale of this Decimal using default HALF_UP rounding.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the operation.
sqrt(this)ArithmeticException - if this < 0Decimal<S> sqrt(RoundingMode roundingMode)
Decimal whose value is the square root of this Decimal value. The result is rounded to
the scale of this Decimal using the specified roundingMode.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the operation.
roundingMode - the rounding mode to apply if the result needs to be roundedsqrt(this)ArithmeticException - if this < 0 or if roundingMode==UNNECESSARY and rounding is necessaryint signum()
Decimal.Decimal is negative, zero, or positive.Decimal<S> shiftLeft(int n)
Decimal whose value is (this << n). The shift distance, n, may be negative, in
which case this method performs a right shift.
Computes floor(this * 2n).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.this << nshiftRight(int)Decimal<S> shiftLeft(int n, RoundingMode roundingMode)
Decimal whose value is (this << n). The shift distance, n, may be negative, in
which case this method performs a right shift.
Computes round(this * 2n) using the specified roundingMode.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.roundingMode - the rounding mode to use if truncation is involved for negative n, that is, for right shiftsthis << nArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryshiftRight(int)Decimal<S> shiftLeft(int n, TruncationPolicy truncationPolicy)
Decimal whose value is (this << n). The shift distance, n, may be negative, in
which case this method performs a right shift.
Computes round(this * 2n) using the RoundingMode specified by the
truncationPolicy argument.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.truncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursthis << nArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDshiftRight(int)Decimal<S> shiftRight(int n)
(this >> n). Sign extension is performed. The shift distance,
n, may be negative, in which case this method performs a left shift.
Computes floor(this / 2n).
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.this >> nshiftLeft(int)Decimal<S> shiftRight(int n, RoundingMode roundingMode)
(this >> n). Sign extension is performed. The shift distance,
n, may be negative, in which case this method performs a left shift.
Computes round(this / 2n) using the specified roundingMode.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.roundingMode - the rounding mode to use if truncation is involvedthis >> nArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryshiftLeft(int)Decimal<S> shiftRight(int n, TruncationPolicy truncationPolicy)
(this >> n). Sign extension is performed. The shift distance,
n, may be negative, in which case this method performs a left shift.
Computes round(this / 2n) using the RoundingMode specified by the
truncationPolicy argument.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - shift distance, in bits.truncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursthis >> nArithmeticException - if truncationPolicy defines RoundingMode.UNNECESSARY and rounding is necessary or if
an overflow occurs and the policy declares OverflowMode.CHECKEDshiftLeft(int)Decimal<S> pow(int n)
Decimal whose value is (thisn) using default HALF_UP rounding.
The current implementation uses the core algorithm defined in ANSI standard X3.274-1996. For n >= 0, the
returned numerical value is within 1 ULP of the exact numerical value. No precision is guaranteed for
n < 0 but the result is usually exact up to 10-20 ULP.
Properties of the X3.274-1996 algorithm are:
IllegalArgumentException is thrown if abs(n) > 999999999n is zero, one is returned even if this is zero, otherwise
n is positive, the result is calculated via the repeated squaring technique into a single
accumulatorn is negative, the result is calculated as if n were positive; this value is then divided
into oneHALF_UP rounding
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - power to raise this Decimal toIllegalArgumentException - if abs(n) > 999999999ArithmeticException - if n is negative and this equals zeroDecimal<S> pow(int n, RoundingMode roundingMode)
Decimal whose value is (thisn) applying the specified roundingMode.
The current implementation uses the core algorithm defined in ANSI standard X3.274-1996. For n >= 0, the
returned numerical value is within 1 ULP of the exact numerical value; the result is actually exact for all
rounding modes other than HALF_UP, HALF_EVEN and HALF_DOWN. No precision is guaranteed for n < 0 but the
result is usually exact up to 10-20 ULP.
Properties of the X3.274-1996 algorithm are:
IllegalArgumentException is thrown if abs(n) > 999999999n is zero, one is returned even if this is zero, otherwise
n is positive, the result is calculated via the repeated squaring technique into a single
accumulatorn is negative, the result is calculated as if n were positive; this value is then divided
into oneroundingMode
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - power to raise this Decimal toroundingMode - the rounding mode to apply if rounding is necessaryIllegalArgumentException - if abs(n) > 999999999ArithmeticException - if n is negative and this equals zero or if roundingMode equals
RoundingMode.UNNECESSARY and rounding is necessaryDecimal<S> pow(int n, TruncationPolicy truncationPolicy)
Decimal whose value is (thisn) applying the RoundingMode specified
by truncationPolicy. The truncationPolicy argument also defines the OverflowMode to apply
if an overflow occurs during the power operation.
The current implementation uses the core algorithm defined in ANSI standard X3.274-1996. For n >= 0, the
returned numerical value is within 1 ULP of the exact numerical value; the result is actually exact for all
rounding modes other than HALF_UP, HALF_EVEN and HALF_DOWN. No precision is guaranteed for n < 0 but the
result is usually exact up to 10-20 ULP.
Properties of the X3.274-1996 algorithm are:
IllegalArgumentException is thrown if abs(n) > 999999999n is zero, one is returned even if this is zero, otherwise
n is positive, the result is calculated via the repeated squaring technique into a single
accumulatorn is negative, the result is calculated as if n were positive; this value is then divided
into oneRoundingMode
specified by truncationPolicy
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the shift operation.
n - power to raise this Decimal totruncationPolicy - the truncation policy specifying RoundingMode and OverflowMode to apply if rounding is
necessary or if an overflow occursIllegalArgumentException - if abs(n) > 999999999ArithmeticException - if n is negative and this equals zero; if truncationPolicy defines
RoundingMode.UNNECESSARY and rounding is necessary or if an overflow occurs and the policy
declares OverflowMode.CHECKEDint compareTo(Decimal<S> other)
Decimal objects numerically.compareTo in interface Comparable<Decimal<S extends ScaleMetrics>>other - Decimal to which this Decimal is to be compared0 if this Decimal is equal to the argument Decimal; a value less than
0 if this Decimal is numerically less than the argument Decimal; and a value
greater than 0 if this Decimal is numerically greater than the argument Decimalboolean isEqualTo(Decimal<S> other)
Decimal with the specified Decimal and returns true if the two are numerically
equal.
Returns true iff compareTo(Decimal) returns 0.
other - Decimal to which this Decimal is to be comparedDecimal is numerically equal to other and false otherwiseboolean isGreaterThan(Decimal<S> other)
Decimal with the specified Decimal and returns true if this Decimal is numerically
greater than other.
Returns true iff compareTo(Decimal) returns a value greater than 0.
other - Decimal to which this Decimal is to be comparedthis > otherboolean isGreaterThanOrEqualTo(Decimal<S> other)
Decimal with the specified Decimal and returns true if this Decimal is numerically
greater than or equal to other.
Returns true iff compareTo(Decimal) returns a non-negative value.
other - Decimal to which this Decimal is to be comparedthis >= otherboolean isLessThan(Decimal<S> other)
Decimal with the specified Decimal and returns true if this Decimal is numerically
less than other.
Returns true iff compareTo(Decimal) returns a negative value.
other - Decimal to which this Decimal is to be compared.this < otherboolean isLessThanOrEqualTo(Decimal<S> other)
Decimal with the specified Decimal and returns true if this Decimal is numerically
less than or equal to other.
Returns true iff compareTo(Decimal) returns a non-positive value.
other - Decimal to which this Decimal is to be comparedthis <= otherDecimal<S> min(Decimal<S> val)
Decimal and val.val - value with which the minimum is to be computed.Decimal whose value is the lesser of this Decimal and val. If they are equal,
as defined by the compareTo method, this is returned.compareTo(Decimal)Decimal<S> max(Decimal<S> val)
Decimal and val.val - value with which the maximum is to be computed.Decimal whose value is the greater of this Decimal and val. If they are
equal, as defined by the compareTo method, this is returned.compareTo(Decimal)Decimal<S> avg(Decimal<S> val)
Decimal and val. The result is rounded to the scale of this Decimal using default HALF_UP rounding. The method is much more
efficient than an addition and subsequent long division and is guaranteed not to overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the average operation.
val - value with which the average is to be computed.Decimal<S> avg(Decimal<S> val, RoundingMode roundingMode)
Decimal and val. The result is rounded to the scale of this Decimal using the specified roundingMode. The method is much more efficient than an
addition and subsequent long division and is guaranteed not to overflow.
The returned value is a new instance if this Decimal is an ImmutableDecimal. If it is a
MutableDecimal then its internal state is altered and this is returned as result now representing
the outcome of the average operation.
val - value with which the average is to be computed.roundingMode - the rounding mode to use if rounding is necessaryround((this + val) / 2)ArithmeticException - if roundingMode==UNNECESSARY and rounding is necessaryboolean isZero()
Decimal is zero.this == 0boolean isOne()
Decimal is one.this == 1boolean isMinusOne()
Decimal is minus one.this == -1boolean isUlp()
Decimal is equal to the smallest positive number representable by a Decimal with the
current scale.unscaledValue() == 1boolean isPositive()
Decimal is strictly positive.this > 0boolean isNonNegative()
Decimal is not negative.this >= 0boolean isNegative()
Decimal is negative.this < 0boolean isNonPositive()
Decimal is not positive.this <= 0boolean isIntegral()
Decimal number is integral, or equivalently if its fractional part is zero.this is an integer numberboolean isIntegralPartZero()
integral part of this Decimal number is zero.-1 < this < 1boolean isBetweenZeroAndOne()
Decimal is between zero (inclusive) and one (exclusive). The result value is true if
and only if this Decimal is not negative and its integral part is zero.0 <= this < 1boolean isBetweenZeroAndMinusOne()
Decimal is between zero (inclusive) and minus one (exclusive). The result value is
true if and only if this Decimal is not positive and its integral part is zero.-1 < this <= 0int compareToNumerically(Decimal<?> other)
Decimal with the specified Decimal. Two Decimal objects that are equal in
value but have a different scale (like 2.0 and 2.00) are considered equal by this method.other - Decimal to which this Decimal is to be compared.0 if this Decimal is equal to the argument Decimal; a value less than
0 if this Decimal is numerically less than the argument Decimal; and a value
greater than 0 if this Decimal is numerically greater than the argument DecimalisEqualToNumerically(Decimal),
compareTo(Decimal)boolean isEqualToNumerically(Decimal<?> other)
Decimal with the specified Decimal and returns true if the two are numerically
equal. Two Decimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are
considered equal by this method as opposed to the equals method which requires identical
scales of the compared values.
Returns true iff compareToNumerically(Decimal) returns 0.
other - Decimal to which this Decimal is to be compared.Decimal is numerically equal to other and false otherwise.compareToNumerically(Decimal),
compareTo(Decimal)int hashCode()
boolean equals(Object obj)
true if and only if the argument is a
Decimal value with the same scale and unscaled value as this
Decimal.equals in class Objectobj - the object to compare withtrue if the argument is a Decimal object that contains the same value and scale as this
object; false otherwiseisEqualTo(Decimal),
isEqualToNumerically(Decimal),
hashCode()