BigDecimal consists of an arbitrary precision integer
unscaled value and a 32-bit
integer scale. If the
scale is zero or positive, the scale is the number of digits to
the right of the decimal point. If the scale is negative, the
unscaled value of the number is multiplied by ten to the power of
the negation of the scale. The value of the number represented by
the BigDecimal is therefore
(unscaledValue × 10-scale).
The BigDecimal class provides operations for
arithmetic, scale manipulation, rounding, comparison, hashing, and
format conversion. The toString method provides a
canonical representation of a BigDecimal.
The BigDecimal class gives its user complete control
over rounding behavior. If no rounding mode is specified and the
exact result cannot be represented, an ArithmeticException
is thrown; otherwise, calculations can be carried out to a chosen
precision and rounding mode by supplying an appropriate MathContext object to the operation. In either case, eight
rounding modes are provided for the control of rounding.
Using the integer fields in this class (such as ROUND_HALF_UP) to represent rounding mode is deprecated; the
enumeration values of the RoundingMode enum, (such
as RoundingMode#HALF_UP) should be used instead.
When a MathContext object is supplied with a precision
setting of 0 (for example, MathContext#UNLIMITED),
arithmetic operations are exact, as are the arithmetic methods
which take no MathContext object. As a corollary of
computing the exact result, the rounding mode setting of a MathContext object with a precision setting of 0 is not used and
thus irrelevant. In the case of divide, the exact quotient could
have an infinitely long decimal expansion; for example, 1 divided
by 3. If the quotient has a nonterminating decimal expansion and
the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the
division is returned, as done for other operations.
When the precision setting is not 0, the rules of BigDecimal arithmetic are broadly compatible with selected modes
of operation of the arithmetic defined in ANSI X3.274-1996 and ANSI
X3.274-1996/AM 1-2000 (section 7.4). Unlike those standards,
BigDecimal includes many rounding modes. Any conflicts
between these ANSI standards and the BigDecimal
specification are resolved in favor of BigDecimal.
Since the same numerical value can have different
representations (with different scales), the rules of arithmetic
and rounding must specify both the numerical result and the scale
used in the result's representation.
The different representations of the same numerical value are
called members of the same cohort. The natural order of BigDecimal
considers members of the same cohort to be equal to each other. In
contrast, the equals method requires both the
numerical value and representation to be the same for equality to
hold. The results of methods like scale() and unscaledValue() will differ for numerically equal values with
different representations.
In general the rounding modes and precision setting determine
how operations return results with a limited number of digits when
the exact result has more digits (perhaps infinitely many in the
case of division and square root) than the number of digits returned.
First, the total number of digits to return is specified by the
MathContext's precision setting; this determines
the result's precision. The digit count starts from the
leftmost nonzero digit of the exact result. The rounding mode
determines how any discarded trailing digits affect the returned
result.
For all arithmetic operators, the operation is carried out as though an exact intermediate result were first calculated and then rounded to the number of digits specified by the precision setting (if necessary), using the selected rounding mode. If the exact result is not returned, some digit positions of the exact result are discarded. When rounding increases the magnitude of the returned result, it is possible for a new digit position to be created by a carry propagating to a leading "9" digit. For example, rounding the value 999.9 to three digits rounding up would be numerically equal to one thousand, represented as 100×101. In such cases, the new "1" is the leading digit position of the returned result.
For methods and constructors with a MathContext
parameter, if the result is inexact but the rounding mode is UNNECESSARY, an ArithmeticException will be thrown.
Besides a logical exact result, each arithmetic operation has a preferred scale for representing a result. The preferred scale for each operation is listed in the table below.
| Operation | Preferred Scale of Result |
|---|---|
| Add | max(addend.scale(), augend.scale()) |
| Subtract | max(minuend.scale(), subtrahend.scale()) |
| Multiply | multiplier.scale() + multiplicand.scale() |
| Divide | dividend.scale() - divisor.scale() |
| Square root | ceil(radicand.scale()/2.0) |
| nth root | ceil((double) radicand.scale()/n) |
1/32 is 0.03125.
Before rounding, the scale of the logical exact intermediate
result is the preferred scale for that operation. If the exact
numerical result cannot be represented in precision
digits, rounding selects the set of digits to return and the scale
of the result is reduced from the scale of the intermediate result
to the least scale which can represent the precision
digits actually returned. If the exact result can be represented
with at most precision digits, the representation
of the result with the scale closest to the preferred scale is
returned. In particular, an exactly representable quotient may be
represented in fewer than precision digits by removing
trailing zeros and decreasing the scale. For example, rounding to
three digits using the floor
rounding mode,
19/100 = 0.19 // integer=19, scale=2
but
21/110 = 0.190 // integer=190, scale=3
Note that for add, subtract, and multiply, the reduction in scale will equal the number of digit positions of the exact result which are discarded. If the rounding causes a carry propagation to create a new high-order digit position, an additional digit of the result is discarded than when no new digit position is created.
Other methods may have slightly different rounding semantics.
For example, the result of the pow method using the
specified algorithm can
occasionally differ from the rounded mathematical result by more
than one unit in the last place, one ulp.
Two types of operations are provided for manipulating the scale
of a BigDecimal: scaling/rounding operations and decimal
point motion operations. Scaling/rounding operations (setScale and round) return a
BigDecimal whose value is approximately (or exactly) equal
to that of the operand, but whose scale or precision is the
specified value; that is, they increase or decrease the precision
of the stored number with minimal effect on its value. Decimal
point motion operations (movePointLeft and
movePointRight) return a
BigDecimal created from the operand by moving the decimal
point a specified distance in the specified direction.
As a 32-bit integer, the set of values for the scale is large,
but bounded. If the scale of a result would exceed the range of a
32-bit integer, either by overflow or underflow, the operation may
throw an ArithmeticException.
For the sake of brevity and clarity, pseudo-code is used
throughout the descriptions of BigDecimal methods. The
pseudo-code expression (i + j) is shorthand for "a
BigDecimal whose value is that of the BigDecimal
i added to that of the BigDecimal
j." The pseudo-code expression (i == j) is
shorthand for "true if and only if the
BigDecimal i represents the same value as the
BigDecimal j." Other pseudo-code expressions
are interpreted similarly. Square brackets are used to represent
the particular BigInteger and scale pair defining a
BigDecimal value; for example [19, 2] is the
BigDecimal numerically equal to 0.19 having a scale of 2.
All methods and constructors for this class throw
NullPointerException when passed a null object
reference for any input parameter.
BigDecimal and IEEE 754 decimal arithmetic is the conceptual
operation of computing the mathematical infinitely precise real
number value of an operation and then mapping that real number to a
representable decimal floating-point value under a rounding
policy. The rounding policy is called a rounding mode for BigDecimal and called a
rounding-direction attribute in IEEE 754-2019. When the exact value
is not representable, the rounding policy determines which of the
two representable decimal values bracketing the exact value is
selected as the computed result. The notion of a preferred
scale/preferred exponent is also shared by both systems.
For differences, IEEE 754 includes several kinds of values not
modeled by BigDecimal including negative zero, signed
infinities, and NaN (not-a-number). IEEE 754 defines formats, which
are parameterized by base (binary or decimal), number of digits of
precision, and exponent range. A format determines the set of
representable values. Most operations accept as input one or more
values of a given format and produce a result in the same format.
A BigDecimal's scale is equivalent to
negating an IEEE 754 value's exponent. BigDecimal values do
not have a format in the same sense; all values have the same
possible range of scale/exponent and the unscaled value has arbitrary precision. Instead,
for the BigDecimal operations taking a MathContext
parameter, if the MathContext has a nonzero precision, the
set of possible representable values for the result is determined
by the precision of the MathContext argument. For example
in BigDecimal, if a nonzero three-digit number and a
nonzero four-digit number are multiplied together in the context of
a MathContext object having a precision of three, the
result will have three digits (assuming no overflow or underflow,
etc.).
The rounding policies implemented by BigDecimal
operations indicated by rounding modes
are a proper superset of the IEEE 754 rounding-direction
attributes.
BigDecimal arithmetic will most resemble IEEE 754
decimal arithmetic if a MathContext corresponding to an
IEEE 754 decimal format, such as decimal64 or decimal128 is
used to round all starting values and intermediate operations. The
numerical values computed can differ if the exponent range of the
IEEE 754 format being approximated is exceeded since a MathContext does not constrain the scale of BigDecimal
results. Operations that would generate a NaN or exact infinity,
such as dividing by zero, throw an ArithmeticException in
BigDecimal arithmetic.
BigDecimal values have a range of algorithmic
complexities; in general, those complexities are a function of both
the size of the unscaled value as well as the size of the
scale. For example, an exact multiply of two BigDecimal values is subject to the
same complexity
constraints as BigInteger multiply of the unscaled
values. In contrast, a BigDecimal value with a compact
representation like new BigDecimal(1E-1000000000) has a
toPlainString result with over one billion characters.
Operations may also allocate and compute on intermediate results, potentially those allocations may be as large as in proportion to the running time of the algorithm.
Users of BigDecimal concerned with bounding the running
time or space of operations can screen out BigDecimal
values with unscaled values or scales above a chosen magnitude.
API Note
Care should be exercised if BigDecimal objects are
used as keys in a SortedMap or elements
in a SortedSet since BigDecimal's natural
ordering is inconsistent with equals. See Comparable, java. or java. for more information.
BigInteger, MathContext, RoundingMode, java.util.SortedMap , java.util.SortedSet
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static volatile BigInteger[] | |
| private static final int | |
| private static final int | |
| private static final long | |
| private static final double[] | DOUBLE_10_POW
Powers of 10 which can be represented exactly in |
| private static final BigInteger[] | FIVE_TO_2_TO
|
| private static final float[] | FLOAT_10_POW
Powers of 10 which can be represented exactly in |
| private static final long | |
| private static final long | |
| pack-priv static final long | INFLATED
Sentinel value for |
| private static final BigInteger | |
| private final transient long | intCompact
If the absolute value of the significand of this BigDecimal is
less than or equal to |
| private final BigInteger | intVal
The unscaled value of this BigDecimal, as returned by |
| private static final JavaLangAccess | |
| private static final double | |
| private static final double | |
| private static final long[] | |
| private static final long[][] | |
| private static final int | |
| public static final BigDecimal | ONE
The value 1, with a scale of 0. |
| private static final int | |
| private static final int | |
| private transient int | precision
The number of decimal digits in this BigDecimal, or 0 if the number of digits are not known (lookaside information). |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| public static final int | ROUND_CEILING
Deprecated
since 9. Use Rounding mode to round towards positive infinity.
RoundingMode#CEILING instead.
|
| public static final int | ROUND_DOWN
Deprecated
since 9. Use Rounding mode to round towards zero.
RoundingMode#DOWN instead.
|
| public static final int | ROUND_FLOOR
Deprecated
since 9. Use Rounding mode to round towards negative infinity.
RoundingMode#FLOOR instead.
|
| public static final int | ROUND_HALF_DOWN
Deprecated
since 9. Use Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round
down.
RoundingMode#HALF_DOWN instead.
|
| public static final int | ROUND_HALF_EVEN
Deprecated
since 9. Use Rounding mode to round towards the "nearest neighbor"
unless both neighbors are equidistant, in which case, round
towards the even neighbor.
RoundingMode#HALF_EVEN instead.
|
| public static final int | ROUND_HALF_UP
Deprecated
since 9. Use Rounding mode to round towards "nearest neighbor"
unless both neighbors are equidistant, in which case round up.
RoundingMode#HALF_UP instead.
|
| public static final int | ROUND_UNNECESSARY
Deprecated
since 9. Use Rounding mode to assert that the requested operation has an exact
result, hence no rounding is necessary.
RoundingMode#UNNECESSARY instead.
|
| public static final int | ROUND_UP
Deprecated
since 9. Use Rounding mode to round away from zero.
RoundingMode#UP instead.
|
| private final int | |
| private static final long | |
| private transient String | stringCache
Used to store the canonical string representation, if computed. |
| public static final BigDecimal | TEN
The value 10, with a scale of 0. |
| private static final long[] | |
| public static final BigDecimal | TWO
The value 2, with a scale of 0. |
| public static final BigDecimal | ZERO
The value 0, with a scale of 0. |
| private static final BigDecimal[] | |
| private static final BigDecimal[] |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| public | BigDecimal(char[]
char array that is the source of characters.first character in the array to inspect. offset, int number of characters to consider. len)Translates a character array representation of a
|
| public | BigDecimal(char[]
char array that is the source of characters.first character in the array to inspect. offset, int number of characters to consider. len, MathContext the context to use. mc)Translates a character array representation of a
|
| public | BigDecimal(char[]
char array that is the source of characters.Translates a character array representation of a
|
| public | BigDecimal(char[]
char array that is the source of characters.the context to use. mc)Translates a character array representation of a
|
| public | BigDecimal(String
String representation of val)BigDecimal.Translates the string representation of a |
| public | BigDecimal(String
string representation of a val, MathContext BigDecimal.the context to use. mc)Translates the string representation of a |
| public | BigDecimal(double
double value to be converted to
BigDecimal.Translates a |
| public | BigDecimal(double
double value to be converted to
BigDecimal.the context to use. mc)Translates a |
| public | BigDecimal(BigInteger
BigInteger value to be converted to
BigDecimal.Translates a |
| public | BigDecimal(BigInteger
BigInteger value to be converted to
BigDecimal.the context to use. mc)Translates a |
| public | BigDecimal(BigInteger
unscaled value of the unscaledVal, int BigDecimal.scale of the scale)BigDecimal.Translates a |
| public | BigDecimal(BigInteger
unscaled value of the unscaledVal, int BigDecimal.scale of the scale, MathContext BigDecimal.the context to use. mc)Translates a |
| public | |
| public | BigDecimal(int
int value to be converted to BigDecimal.the context to use. mc)Translates an |
| public | |
| public | BigDecimal(long
long value to be converted to BigDecimal.the context to use. mc)Translates a |
| Modifier and Type | Method and Description |
|---|---|
| public BigDecimal | Returns: abs(this)Returns a |
| public BigDecimal | Returns: abs(this), rounded as necessary.the context to use. mc)Returns a |
| public BigDecimal | Returns: this + augendvalue to be added to this augend)BigDecimal.Returns a |
| public BigDecimal | Returns: this + augend, rounded as necessary.value to be added to this augend, MathContext BigDecimal.the context to use. mc)Returns a |
| private static long | |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | |
| private BigDecimal | Returns: a BigDecimal numerically equivalent tothis, whose precision
does not exceed maxPrecision and whose scale is the closest
to preferredScale.the scale to reach preferredScale, int the largest precision the result can have.
maxPrecision)maxPrecision == 0 means that the result can have arbitrary precision.Assumes |
| private BigDecimal | |
| private static int | Returns: the length of the unscaled value, in decimal digitsthe BigInteger b)Returns the length of the absolute value of a BigInteger, in decimal digits. |
| private BigInteger | |
| private static BigInteger | |
| private static BigInteger | |
| private static BigInteger | Returns: aBigInteger with the value (10n)the power of ten to be returned (>=0) n)Return 10 to the power n, as a |
| public byte | Returns: thisBigDecimal converted to a byte.Converts this |
| private int | Returns: validated scale as an int.The new scale. val)Check a scale for Underflow or Overflow. |
| private static int | |
| private static int | |
| private static int | |
| private static boolean | commonNeedIncrement(int roundingMode, int qsign, int cmpFracHalf, boolean oddQuot)
Shared logic of need increment computation. |
| private static long | |
| private int | |
| private static int | |
| private static int | |
| private static int | |
| public int | Returns: -1, 0, or 1 as thisBigDecimal is numerically
less than, equal to, or greater than val.BigDecimal to which this BigDecimal is
to be compared.Implements java. Compares this |
| private static BigDecimal | Returns: newBigDecimal with a scale possibly reduced
to be closed to the preferred scale.Remove insignificant trailing zeros from this
|
| private static BigDecimal | Returns: newBigDecimal with a scale possibly reduced
to be closed to the preferred scale.Remove insignificant trailing zeros from this
|
| private static int | |
| public BigDecimal | Returns: this / divisorvalue by which this divisor, int BigDecimal is to be divided.scale of the scale, int BigDecimal quotient to be returned.rounding mode to apply. roundingMode)
Deprecated
since 9. The method
divide(BigDecimal, int, RoundingMode)
should be used in preference to this legacy method.
Returns a |
| public BigDecimal | Returns: this / divisorvalue by which this divisor, int BigDecimal is to be divided.scale of the scale, RoundingMode BigDecimal quotient to be returned.rounding mode to apply. roundingMode)Returns a |
| public BigDecimal | Returns: this / divisorvalue by which this divisor, int BigDecimal is to be divided.rounding mode to apply. roundingMode)
Deprecated
since 9. The method
divide(BigDecimal, RoundingMode)
should be used in preference to this legacy method.
Returns a |
| public BigDecimal | Returns: this / divisorvalue by which this divisor, RoundingMode BigDecimal is to be divided.rounding mode to apply. roundingMode)Returns a |
| public BigDecimal | Returns: this / divisorvalue by which this divisor)BigDecimal is to be divided.Returns a |
| public BigDecimal | Returns: this / divisor, rounded as necessary.value by which this divisor, MathContext BigDecimal is to be divided.the context to use. mc)Returns a |
| private static BigDecimal | divide(final long xs, int xscale, final long ys, int yscale, long preferredScale, MathContext mc)
Returns a |
| private static BigDecimal | divide(BigInteger xs, int xscale, long ys, int yscale, long preferredScale, MathContext mc)
Returns a |
| private static BigDecimal | divide(long xs, int xscale, BigInteger ys, int yscale, long preferredScale, MathContext mc)
Returns a |
| private static BigDecimal | divide(BigInteger xs, int xscale, BigInteger ys, int yscale, long preferredScale, MathContext mc)
Returns a |
| private static BigDecimal | divide(long dividend, int dividendScale, long divisor, int divisorScale, int scale, int roundingMode)
|
| private static BigDecimal | divide(BigInteger dividend, int dividendScale, long divisor, int divisorScale, int scale, int roundingMode)
|
| private static BigDecimal | divide(long dividend, int dividendScale, BigInteger divisor, int divisorScale, int scale, int roundingMode)
|
| private static BigDecimal | divide(BigInteger dividend, int dividendScale, BigInteger divisor, int divisorScale, int scale, int roundingMode)
|
| public BigDecimal[] | Returns: a two elementBigDecimal array: the quotient
(the result of divideToIntegralValue) is the initial element
and the remainder is the final element.value by which this divisor)BigDecimal is to be divided,
and the remainder computed.Returns a two-element |
| public BigDecimal[] | Returns: a two elementBigDecimal array: the quotient
(the result of divideToIntegralValue) is the
initial element and the remainder is the final element.value by which this divisor, MathContext BigDecimal is to be divided,
and the remainder computed.the context to use. mc)Returns a two-element |
| private static BigDecimal | divideAndRound(long ldividend, long ldivisor, int scale, int roundingMode, int preferredScale)
Internally used for division operation for division |
| private static long | divideAndRound(long ldividend, long ldivisor, int roundingMode)
Divides |
| private static BigInteger | divideAndRound(BigInteger bdividend, long ldivisor, int roundingMode)
Divides |
| private static BigDecimal | divideAndRound(BigInteger bdividend, long ldivisor, int scale, int roundingMode, int preferredScale)
Internally used for division operation for division |
| private static BigInteger | divideAndRound(BigInteger bdividend, BigInteger bdivisor, int roundingMode)
Divides |
| private static BigDecimal | divideAndRound(BigInteger bdividend, BigInteger bdivisor, int scale, int roundingMode, int preferredScale)
Internally used for division operation for division |
| private static BigDecimal | divideAndRound128(final long dividendHi, final long dividendLo, long divisor, int sign, int scale, int roundingMode, int preferredScale)
|
| private static BigInteger | |
| private static BigDecimal | divideSmallFastPath(final long xs, int xscale, final long ys, int yscale, long preferredScale, MathContext mc)
Returns a |
| public BigDecimal | Returns: The integer part ofthis / divisor.value by which this divisor)BigDecimal is to be divided.Returns a |
| public BigDecimal | Returns: The integer part ofthis / divisor.value by which this divisor, MathContext BigDecimal is to be divided.the context to use. mc)Returns a |
| private static BigDecimal | Returns: aBigDecimal rounded according to the MathContext
settings. May return value, if no rounding needed.the value to be rounded val, MathContext the context to use. mc)Returns a |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | doRound128(long hi, long lo, int sign, int scale, MathContext mc)
rounds 128-bit value according |
| public double | Returns: thisBigDecimal converted to a double.Implements abstract java. Converts this |
| public boolean | Returns: true if and only if the specified Object is a
BigDecimal whose value and scale are equal to this
BigDecimal's.Object to which this BigDecimal is
to be compared.Overrides java. Compares this |
| private static BigInteger | Returns: aBigDecimal with the value (10n) and
in the meantime, the BIG_TEN_POWERS_TABLE array gets
expanded to the size greater than n.the power of ten to be returned (>=0) n)Expand the BIG_TEN_POWERS_TABLE array to contain at least 10**n. |
| private static BigInteger | |
| public float | Returns: thisBigDecimal converted to a float.Implements abstract java. Converts this |
| private boolean | fractionOnly()
Return true if a nonzero BigDecimal has an absolute value less than one; i.e. only has fraction digits. |
| private double | |
| private float | |
| private static String | |
| public int | Returns: hash code for thisBigDecimal.Overrides java. Returns the hash code for this |
| private BigInteger | inflated()
Returns appropriate BigInteger from intVal field if intVal is null, i.e. the compact representation is in use. |
| public int | Returns: thisBigDecimal converted to an int.Implements abstract java. Converts this |
| public int | Returns: thisBigDecimal converted to an int.Converts this |
| private static boolean | |
| pack-priv boolean | |
| private boolean | |
| private String | Returns: string with canonical string representation of thisBigDecimaltrue for Scientific exponential notation;
false for EngineeringLay out this |
| private static int | |
| pack-priv static int | Returns: the length of the unscaled value, in decimal digits.the x)longReturns the length of the absolute value of a |
| private static boolean | |
| private static long | longMultiplyPowerTen(long val, int n)
Compute val * 10 ^ n; return this product if it is representable as a long, INFLATED otherwise. |
| public long | Returns: thisBigDecimal converted to a long.Implements abstract java. Converts this |
| public long | Returns: thisBigDecimal converted to a long.Converts this |
| private static long | |
| private static void | matchScale(BigDecimal[]
array of two elements referring to the two
val)BigDecimals to be aligned.Match the scales of two |
| public BigDecimal | Returns: theBigDecimal whose value is the greater of this
BigDecimal and val. If they are equal,
as defined by the compareTo
method, this is returned.value with which the maximum is to be computed. val)Returns the maximum of this |
| public BigDecimal | Returns: theBigDecimal whose value is the lesser of this
BigDecimal and val. If they are equal,
as defined by the compareTo
method, this is returned.value with which the minimum is to be computed. val)Returns the minimum of this |
| public BigDecimal | Returns: aBigDecimal which is equivalent to this one with the
decimal point moved n places to the left.number of places to move the decimal point to the left. n)Returns a |
| public BigDecimal | Returns: aBigDecimal which is equivalent to this one
with the decimal point moved n places to the right.number of places to move the decimal point to the right. n)Returns a |
| private static long | |
| public BigDecimal | Returns: this * multiplicandvalue to be multiplied by this multiplicand)BigDecimal.Returns a |
| public BigDecimal | Returns: this * multiplicand, rounded as necessary.value to be multiplied by this multiplicand, MathContext BigDecimal.the context to use. mc)Returns a |
| private static long | |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | multiplyAndRound(long x, long y, int scale, MathContext mc)
Multiplies two long values and rounds according |
| private static BigDecimal | |
| private static BigDecimal | |
| private static BigDecimal | multiplyDivideAndRound(long dividend0, long dividend1, long divisor, int scale, int roundingMode, int preferredScale)
|
| private static boolean | needIncrement(long ldivisor, int roundingMode, int qsign, long q, long r)
Tests if quotient has to be incremented according the roundingMode |
| private static boolean | needIncrement(long ldivisor, int roundingMode, int qsign, MutableBigInteger mq, long r)
Tests if quotient has to be incremented according the roundingMode |
| private static boolean | needIncrement(MutableBigInteger mdivisor, int roundingMode, int qsign, MutableBigInteger mq, MutableBigInteger mr)
Tests if quotient has to be incremented according the roundingMode |
| public BigDecimal | Returns: -this.Returns a |
| public BigDecimal | Returns: -this, rounded as necessary.the context to use. mc)Returns a |
| private static long | |
| public BigDecimal | |
| public BigDecimal | Returns: this, rounded as necessary. A zero result will
have a scale of 0.the context to use. mc)Returns a |
| public BigDecimal | Returns: thisnpower to raise this n)BigDecimal to.Returns a |
| public BigDecimal | Returns: thisn using the ANSI standard X3.274-1996
algorithmpower to raise this n, MathContext BigDecimal to.the context to use. mc)Returns a |
| private BigDecimal[] | preAlign(BigDecimal lhs, BigDecimal augend, long padding, MathContext mc)
Returns an array of length two, the sum of whose entries is
equal to the rounded sum of the |
| public int | |
| private static int | |
| private static void | |
| private void | readObject(ObjectInputStream
the stream being read. s)Reconstitute the |
| private void | |
| public BigDecimal | Returns: this % divisor.value by which this divisor)BigDecimal is to be divided.Returns a |
| public BigDecimal | Returns: this % divisor, rounded as necessary.value by which this divisor, MathContext BigDecimal is to be divided.the context to use. mc)Returns a |
| public BigDecimal | Returns: thenth root of this.the root degree n, MathContext the context to use. mc)Returns an approximation to the |
| private boolean | rootnResultAssertions(BigDecimal result, MathContext mc, int n)
For nonzero values, check numerical correctness properties of the computed result for the chosen rounding mode. |
| public BigDecimal | Returns: aBigDecimal rounded according to the
MathContext settings.the context to use. mc)Returns a |
| private static BigDecimal | |
| private static int | |
| public int | |
| public BigDecimal | Returns: a BigDecimal whose numerical value is equal to (this * 10n)the exponent power of ten to scale by n)Returns a BigDecimal whose numerical value is equal to
( |
| pack-priv static BigDecimal | |
| public BigDecimal | Returns: aBigDecimal whose scale is the specified value,
and whose unscaled value is determined by multiplying or
dividing this BigDecimal's unscaled value by the
appropriate power of ten to maintain its overall value.scale of the newScale, RoundingMode BigDecimal value to be returned.The rounding mode to apply. roundingMode)Returns a |
| public BigDecimal | Returns: aBigDecimal whose scale is the specified value,
and whose unscaled value is determined by multiplying or
dividing this BigDecimal's unscaled value by the
appropriate power of ten to maintain its overall value.scale of the newScale, int BigDecimal value to be returned.The rounding mode to apply. roundingMode)
Deprecated
since 9. The method
setScale(int, RoundingMode) should
be used in preference to this legacy method.
Returns a |
| public BigDecimal | Returns: aBigDecimal whose scale is the specified value, and
whose unscaled value is determined by multiplying or dividing
this BigDecimal's unscaled value by the appropriate
power of ten to maintain its overall value.scale of the newScale)BigDecimal value to be returned.Returns a |
| public short | Returns: thisBigDecimal converted to a short.Converts this |
| public int | Returns: -1, 0, or 1 as the value of thisBigDecimal
is negative, zero, or positive.Returns the signum function of this |
| public BigDecimal | Returns: the square root ofthis.the context to use. mc)Returns an approximation to the square root of |
| public BigDecimal | Returns: a numerically equalBigDecimal with any
trailing zeros removed.Returns a |
| private static BigDecimal | stripZerosToMatchScale(BigInteger intVal, long intCompact, int scale, long preferredScale)
Assumes |
| public BigDecimal | Returns: this - subtrahendvalue to be subtracted from this subtrahend)BigDecimal.Returns a |
| public BigDecimal | Returns: this - subtrahend, rounded as necessary.value to be subtracted from this subtrahend, MathContext BigDecimal.the context to use. mc)Returns a |
| public BigInteger | Returns: thisBigDecimal converted to a BigInteger.Converts this |
| public BigInteger | Returns: thisBigDecimal converted to a BigInteger.Converts this |
| public String | Returns: string representation of thisBigDecimal, using
engineering notation if an exponent is needed.Returns a string representation of this |
| public String | Returns: a string representation of thisBigDecimal
without an exponent field.Returns a string representation of this |
| private static BigInteger | |
| public String | Returns: string representation of thisBigDecimal.Overrides java. Returns the string representation of this |
| public BigDecimal | Returns: the size of an ulp ofthisReturns the size of an ulp, a unit in the last place, of this
|
| public BigInteger | Returns: the unscaled value of thisBigDecimal.Returns a |
| private static boolean | |
| private static boolean | |
| public static BigDecimal | Returns: aBigDecimal whose value is
(unscaledVal × 10-scale).unscaled value of the unscaledVal, int BigDecimal.scale of the scale)BigDecimal.Translates a |
| public static BigDecimal | Returns: aBigDecimal whose value is val.value of the val)BigDecimal.Translates a |
| pack-priv static BigDecimal | |
| pack-priv static BigDecimal | |
| public static BigDecimal | Returns: aBigDecimal whose value is equal to or approximately
equal to the value of val.double to convert to a BigDecimal.Translates a |
| private void | writeObject(ObjectOutputStream
the stream to serialize to. s)Serialize this |
| pack-priv static BigDecimal |