| java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | - | - | java.lang.Number | ||||||||||||||||||||||||||||||||||||||||||||||||
| | | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | - | - | java.math.BigDecimal | ||||||||||||||||||||||||||||||||||||||||||||||||
BigDecimal represnet immutable, arbitrary-precision signed decimal numbers.
Constants for One, Ten and Zero
| Type | Field | Summary |
|---|---|---|
| static BigDecimal | ONE | The value 1, with a scale of 0. |
| static BigDecimal | TEN | The value 10, with a scale of 0. |
| static BigDecimal | ZERO | The value 0, with a scale of 0. |
Rounding mode
| Type | Field | Summary |
|---|---|---|
| static int | ROUND_CEILING | Round towards positive infinity. |
| static int | ROUND_DOWN | Round towards zero. |
| static int | ROUND_FLOOR | Round towards negative infinity. |
| static int | ROUND_HALF_DOWN | Round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. |
| static int | ROUND_HALF_EVEN | Round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. |
| static int | ROUND_HALF_UP | Round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. |
| static int | ROUND_UNNECESSARY | No rounding is necessary. |
| static int | ROUND_UP | Rounding mode to round away from zero. |
| Constructor | Summary |
|---|---|
| BigDecimal(BigInteger val) | Converts a BigInteger into a BigDecimal. |
| BigDecimal(BigInteger unscaledVal, int scale) | Converts a BigInteger with scale into a BigDecimal. |
| BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) | Converts a BigInteger and an int scale into a BigDecimal, with rounding according to the context settings. |
| BigDecimal(BigInteger val, MathContext mc) | Converts a BigInteger into a BigDecimal rounding according to the context settings. |
| BigDecimal(char[] in) | Converts a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor. |
| BigDecimal(char[] in, int offset, int len) | Converts a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified. |
| BigDecimal(char[] in, int offset, int len, MathContext mc) | Converts a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified and with rounding according to the context settings. |
| BigDecimal(char[] in, MathContext mc) | Converts a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor and with rounding according to the context settings. |
| BigDecimal(double val) | Converts a double into a BigDecimal which is the exact decimal representation of the double's binary floating-point value. |
| BigDecimal(double val, MathContext mc) | Converts a double into a BigDecimal, with rounding according to the context settings. |
| BigDecimal(int val) | Converts an int into a BigDecimal. |
| BigDecimal(int val, MathContext mc) | Converts an int into a BigDecimal, with rounding according to the context settings. |
| BigDecimal(long val) | Converts a long into a BigDecimal. |
| BigDecimal(long val, MathContext mc) | Converts a long into a BigDecimal, with rounding according to the context settings. |
| BigDecimal(String val) | Converts the string representation of a BigDecimal into a BigDecimal. |
| BigDecimal(String val, MathContext mc) | Converts the string representation of a BigDecimal into a BigDecimal, accepting the same strings as the BigDecimal(String) constructor, with rounding according to the context settings. |
Methods used to do calculation
| Return | Method |
|---|---|
| BigDecimal | abs() |
| BigDecimal | abs(MathContext mc) |
| BigDecimal | add(BigDecimal augend) |
| BigDecimal | add(BigDecimal augend, MathContext mc) |
| BigDecimal | divide(BigDecimal divisor) |
| BigDecimal | divide(BigDecimal divisor, int roundingMode) |
| BigDecimal | divide(BigDecimal divisor, int scale, int roundingMode) |
| BigDecimal | divide(BigDecimal divisor, int scale, RoundingMode roundingMode) |
| BigDecimal | divide(BigDecimal divisor, MathContext mc) |
| BigDecimal | divide(BigDecimal divisor, RoundingMode roundingMode) |
| BigDecimal[] | divideAndRemainder(BigDecimal divisor) |
| BigDecimal[] | divideAndRemainder(BigDecimal divisor, MathContext mc) |
| BigDecimal | divideToIntegralValue(BigDecimal divisor) |
| BigDecimal | divideToIntegralValue(BigDecimal divisor, MathContext mc) |
| BigDecimal | max(BigDecimal val) |
| BigDecimal | min(BigDecimal val) |
| BigDecimal | multiply(BigDecimal multiplicand) |
| BigDecimal | multiply(BigDecimal multiplicand, MathContext mc) |
| BigDecimal | negate() |
| BigDecimal | negate(MathContext mc) |
| BigDecimal | plus() |
| BigDecimal | plus(MathContext mc) |
| BigDecimal | pow(int n) |
| BigDecimal | pow(int n, MathContext mc) |
| BigDecimal | remainder(BigDecimal divisor) |
| BigDecimal | remainder(BigDecimal divisor, MathContext mc) |
| BigDecimal | round(MathContext mc) |
| BigDecimal | scaleByPowerOfTen(int n) |
| BigDecimal | subtract(BigDecimal subtrahend) |
| BigDecimal | subtract(BigDecimal subtrahend, MathContext mc) |
Convert BigDecimal to primitive data types
| Return | Method | Summary |
|---|---|---|
| byte | byteValueExact() | Converts this BigDecimal to a byte, checking for lost information. |
| double | doubleValue() | Converts this BigDecimal to a double. |
| float | floatValue() | Converts this BigDecimal to a float. |
| int | intValue() | Converts this BigDecimal to an int. |
| int | intValueExact() | Converts this BigDecimal to an int, checking for lost information. |
| long | longValue() | Converts this BigDecimal to a long. |
| long | longValueExact() | Converts this BigDecimal to a long, checking for lost information. |
| short | shortValueExact() | Converts this BigDecimal to a short, checking for lost information. |
| BigInteger | toBigInteger() | Converts this BigDecimal to a BigInteger. |
| BigInteger | toBigIntegerExact() | Converts this BigDecimal to a BigInteger, checking for lost information. |
Compare two BigDecimal
| Return | Method | Summary |
|---|---|---|
| int | compareTo(BigDecimal val) | Compares this BigDecimal with the specified BigDecimal. |
| boolean | equals(Object x) | Compares this BigDecimal with the specified Object for equality. |
Move decimal point
| Return | Method | Summary |
|---|---|---|
| BigDecimal | movePointLeft(int n) | decimal point moved n places to the left. |
| BigDecimal | movePointRight(int n) | decimal point moved n places to the right. |
Scale and precision
| Return | Method | Summary |
|---|---|---|
| int | precision() | Returns the precision. |
| int | scale() | Returns the scale. |
| BigDecimal | setScale(int newScale) | Change the scale. |
| BigDecimal | setScale(int newScale, int roundingMode) | Set scale with rounding Mode. |
| BigDecimal | setScale(int newScale, RoundingMode roundingMode) | Set scale with rounding Mode. |
| int | signum() | Returns the signum function of this BigDecimal. |
| BigInteger | unscaledValue() | Get the unscaled value. |
| BigDecimal | ulp() | Returns the size of an ulp(a unit in the last place). |
Convert BigDecimal to String
| Return | Method | Summary |
|---|---|---|
| String | toEngineeringString() | Using engineering notation if an exponent is needed. |
| String | toPlainString() | Without an exponent field. |
| String | toString() | Using scientific notation if an exponent is needed. |
Remove the trailing zeros
| Return | Method | Summary |
|---|---|---|
| BigDecimal | stripTrailingZeros() | trailing zeros removed. |
Convert double and long to BigDecimal
| Return | Method | Summary |
|---|---|---|
| static BigDecimal | valueOf(double val) | Translates a double into a BigDecimal. |
| static BigDecimal | valueOf(long val) | Translates a long value into a BigDecimal with a scale of zero. |
| static BigDecimal | valueOf(long unscaledVal, int scale) | Translates a long unscaled value and an int scale into a BigDecimal. |
| w__w_w___.___jav__a__2_s__._c_o_m___ | Contact Us |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |