Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » math » [javadoc | source]
java.math
public class: BigDecimal [javadoc | source]
java.lang.Object
   java.lang.Number
      java.math.BigDecimal

All Implemented Interfaces:
    Comparable, Serializable

This class represents immutable arbitrary precision decimal numbers. Each {@code BigDecimal} instance is represented with a unscaled arbitrary precision mantissa (the unscaled value) and a scale. The value of the {@code BigDecimal} is {@code unscaledValue} 10^(-{@code scale}).
Field Summary
public static final  BigDecimal ZERO    The constant zero as a {@code BigDecimal}. 
public static final  BigDecimal ONE    The constant one as a {@code BigDecimal}. 
public static final  BigDecimal TEN    The constant ten as a {@code BigDecimal}. 
public static final  int ROUND_UP    Rounding mode where positive values are rounded towards positive infinity and negative values towards negative infinity.
    Also see:
    RoundingMode#UP
 
public static final  int ROUND_DOWN    Rounding mode where the values are rounded towards zero.
    Also see:
    RoundingMode#DOWN
 
public static final  int ROUND_CEILING    Rounding mode to round towards positive infinity. For positive values this rounding mode behaves as #ROUND_UP , for negative values as #ROUND_DOWN .
    Also see:
    RoundingMode#CEILING
 
public static final  int ROUND_FLOOR    Rounding mode to round towards negative infinity. For positive values this rounding mode behaves as #ROUND_DOWN , for negative values as #ROUND_UP .
    Also see:
    RoundingMode#FLOOR
 
public static final  int ROUND_HALF_UP    Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding up.
    Also see:
    RoundingMode#HALF_UP
 
public static final  int ROUND_HALF_DOWN    Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding down.
    Also see:
    RoundingMode#HALF_DOWN
 
public static final  int ROUND_HALF_EVEN    Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding to the even neighbor.
    Also see:
    RoundingMode#HALF_EVEN
 
public static final  int ROUND_UNNECESSARY    Rounding mode where the rounding operations throws an {@code ArithmeticException} for the case that rounding is necessary, i.e. for the case that the value cannot be represented exactly.
    Also see:
    RoundingMode#UNNECESSARY
 
Constructor:
 public BigDecimal(char[] in) 
 public BigDecimal(String val) 
    Constructs a new {@code BigDecimal} instance from a string representation.
    Parameters:
    val - string containing the string representation of this {@code BigDecimal}.
    Throws:
    NumberFormatException - if {@code val} does not contain a valid string representation of a big decimal.
 public BigDecimal(double val) 
 public BigDecimal(BigInteger val) 
    Constructs a new {@code BigDecimal} instance from the given big integer {@code val}. The scale of the result is {@code 0}.
    Parameters:
    val - {@code BigInteger} value to be converted to a {@code BigDecimal} instance.
 public BigDecimal(int val) 
 public BigDecimal(long val) 
 public BigDecimal(char[] in,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from a string representation given as a character array. The result is rounded according to the specified math context.
    Parameters:
    in - array of characters containing the string representation of this {@code BigDecimal}.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    NullPointerException - if {@code in == null}.
    NumberFormatException - if {@code in} does not contain a valid string representation of a big decimal.
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(String val,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from a string representation. The result is rounded according to the specified math context.
    Parameters:
    val - string containing the string representation of this {@code BigDecimal}.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    NumberFormatException - if {@code val} does not contain a valid string representation of a big decimal.
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(double val,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from the 64bit double {@code val}. The constructed big decimal is equivalent to the given double. For example, {@code new BigDecimal(0.1)} is equal to {@code 0.1000000000000000055511151231257827021181583404541015625}. This happens as {@code 0.1} cannot be represented exactly in binary.

    To generate a big decimal instance which is equivalent to {@code 0.1} use the {@code BigDecimal(String)} constructor.

    Parameters:
    val - double value to be converted to a {@code BigDecimal} instance.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    NumberFormatException - if {@code val} is infinity or not a number.
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(BigInteger val,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from the given big integer {@code val}. The scale of the result is {@code 0}.
    Parameters:
    val - {@code BigInteger} value to be converted to a {@code BigDecimal} instance.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(BigInteger unscaledVal,
    int scale) 
    Constructs a new {@code BigDecimal} instance from a given unscaled value {@code unscaledVal} and a given scale. The value of this instance is {@code unscaledVal} 10^(-{@code scale}).
    Parameters:
    unscaledVal - {@code BigInteger} representing the unscaled value of this {@code BigDecimal} instance.
    scale - scale of this {@code BigDecimal} instance.
    Throws:
    NullPointerException - if {@code unscaledVal == null}.
 public BigDecimal(int val,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from the given int {@code val}. The scale of the result is {@code 0}. The result is rounded according to the specified math context.
    Parameters:
    val - int value to be converted to a {@code BigDecimal} instance.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    ArithmeticException - if {@code mc.precision > 0} and {@code c.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(long val,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from the given long {@code val}. The scale of the result is {@code 0}. The result is rounded according to the specified math context.
    Parameters:
    val - long value to be converted to a {@code BigDecimal} instance.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
 public BigDecimal(char[] in,
    int offset,
    int len) 
 public BigDecimal(BigInteger unscaledVal,
    int scale,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from a given unscaled value {@code unscaledVal} and a given scale. The value of this instance is {@code unscaledVal} 10^(-{@code scale}). The result is rounded according to the specified math context.
    Parameters:
    unscaledVal - {@code BigInteger} representing the unscaled value of this {@code BigDecimal} instance.
    scale - scale of this {@code BigDecimal} instance.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
    NullPointerException - if {@code unscaledVal == null}.
 public BigDecimal(char[] in,
    int offset,
    int len,
    MathContext mc) 
    Constructs a new {@code BigDecimal} instance from a string representation given as a character array.
    Parameters:
    in - array of characters containing the string representation of this {@code BigDecimal}.
    offset - first index to be copied.
    len - number of characters to be used.
    mc - rounding mode and precision for the result of this operation.
    Throws:
    NullPointerException - if {@code in == null}.
    NumberFormatException - if {@code offset < 0} or {@code len <= 0} or {@code offset+len-1 < 0} or {@code offset+len-1 >= in.length}.
    NumberFormatException - if {@code in} does not contain a valid string representation of a big decimal.
    ArithmeticException - if {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY} and the new big decimal cannot be represented within the given precision without rounding.
Method from java.math.BigDecimal Summary:
abs,   abs,   add,   add,   byteValueExact,   compareTo,   divide,   divide,   divide,   divide,   divide,   divide,   divideAndRemainder,   divideAndRemainder,   divideToIntegralValue,   divideToIntegralValue,   doubleValue,   equals,   floatValue,   hashCode,   intValue,   intValueExact,   longValue,   longValueExact,   max,   min,   movePointLeft,   movePointRight,   multiply,   multiply,   negate,   negate,   plus,   plus,   pow,   pow,   precision,   remainder,   remainder,   round,   scale,   scaleByPowerOfTen,   setScale,   setScale,   setScale,   shortValueExact,   signum,   stripTrailingZeros,   subtract,   subtract,   toBigInteger,   toBigIntegerExact,   toEngineeringString,   toPlainString,   toString,   ulp,   unscaledValue,   valueOf,   valueOf,   valueOf
Methods from java.lang.Number:
byteValue,   doubleValue,   floatValue,   intValue,   longValue,   shortValue
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.math.BigDecimal Detail:
 public BigDecimal abs() 
    Returns a new {@code BigDecimal} whose value is the absolute value of {@code this}. The scale of the result is the same as the scale of this.
 public BigDecimal abs(MathContext mc) 
    Returns a new {@code BigDecimal} whose value is the absolute value of {@code this}. The result is rounded according to the passed context {@code mc}.
 public BigDecimal add(BigDecimal augend) 
    Returns a new {@code BigDecimal} whose value is {@code this + augend}. The scale of the result is the maximum of the scales of the two arguments.
 public BigDecimal add(BigDecimal augend,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this + augend}. The result is rounded according to the passed context {@code mc}.
 public byte byteValueExact() 
    Returns this {@code BigDecimal} as a byte value if it has no fractional part and if its value fits to the byte range ([-128..127]). If these conditions are not met, an {@code ArithmeticException} is thrown.
 public int compareTo(BigDecimal val) 
    Compares this {@code BigDecimal} with {@code val}. Returns one of the three values {@code 1}, {@code 0}, or {@code -1}. The method behaves as if {@code this.subtract(val)} is computed. If this difference is > 0 then 1 is returned, if the difference is < 0 then -1 is returned, and if the difference is 0 then 0 is returned. This means, that if two decimal instances are compared which are equal in value but differ in scale, then these two instances are considered as equal.
 public BigDecimal divide(BigDecimal divisor) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. The scale of the result is the difference of the scales of {@code this} and {@code divisor}. If the exact result requires more digits, then the scale is adjusted accordingly. For example, {@code 1/128 = 0.0078125} which has a scale of {@code 7} and precision {@code 5}.
 public BigDecimal divide(BigDecimal divisor,
    int roundingMode) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. The scale of the result is the scale of {@code this}. If rounding is required to meet the specified scale, then the specified rounding mode {@code roundingMode} is applied.
 public BigDecimal divide(BigDecimal divisor,
    RoundingMode roundingMode) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. The scale of the result is the scale of {@code this}. If rounding is required to meet the specified scale, then the specified rounding mode {@code roundingMode} is applied.
 public BigDecimal divide(BigDecimal divisor,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. The result is rounded according to the passed context {@code mc}. If the passed math context specifies precision {@code 0}, then this call is equivalent to {@code this.divide(divisor)}.
 public BigDecimal divide(BigDecimal divisor,
    int scale,
    int roundingMode) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. As scale of the result the parameter {@code scale} is used. If rounding is required to meet the specified scale, then the specified rounding mode {@code roundingMode} is applied.
 public BigDecimal divide(BigDecimal divisor,
    int scale,
    RoundingMode roundingMode) 
    Returns a new {@code BigDecimal} whose value is {@code this / divisor}. As scale of the result the parameter {@code scale} is used. If rounding is required to meet the specified scale, then the specified rounding mode {@code roundingMode} is applied.
 public BigDecimal[] divideAndRemainder(BigDecimal divisor) 
    Returns a {@code BigDecimal} array which contains the integral part of {@code this / divisor} at index 0 and the remainder {@code this % divisor} at index 1. The quotient is rounded down towards zero to the next integer.
 public BigDecimal[] divideAndRemainder(BigDecimal divisor,
    MathContext mc) 
    Returns a {@code BigDecimal} array which contains the integral part of {@code this / divisor} at index 0 and the remainder {@code this % divisor} at index 1. The quotient is rounded down towards zero to the next integer. The rounding mode passed with the parameter {@code mc} is not considered. But if the precision of {@code mc > 0} and the integral part requires more digits, then an {@code ArithmeticException} is thrown.
 public BigDecimal divideToIntegralValue(BigDecimal divisor) 
    Returns a new {@code BigDecimal} whose value is the integral part of {@code this / divisor}. The quotient is rounded down towards zero to the next integer. For example, {@code 0.5/0.2 = 2}.
 public BigDecimal divideToIntegralValue(BigDecimal divisor,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is the integral part of {@code this / divisor}. The quotient is rounded down towards zero to the next integer. The rounding mode passed with the parameter {@code mc} is not considered. But if the precision of {@code mc > 0} and the integral part requires more digits, then an {@code ArithmeticException} is thrown.
 public double doubleValue() 
    Returns this {@code BigDecimal} as a double value. If {@code this} is too big to be represented as an float, then {@code Double.POSITIVE_INFINITY} or {@code Double.NEGATIVE_INFINITY} is returned.

    Note, that if the unscaled value has more than 53 significant digits, then this decimal cannot be represented exactly in a double variable. In this case the result is rounded.

    For example, if the instance {@code x1 = new BigDecimal("0.1")} cannot be represented exactly as a double, and thus {@code x1.equals(new BigDecimal(x1.doubleValue())} returns {@code false} for this case.

    Similarly, if the instance {@code new BigDecimal(9007199254740993L)} is converted to a double, the result is {@code 9.007199254740992E15}.

 public boolean equals(Object x) 
    Returns {@code true} if {@code x} is a {@code BigDecimal} instance and if this instance is equal to this big decimal. Two big decimals are equal if their unscaled value and their scale is equal. For example, 1.0 (10*10^(-1)) is not equal to 1.00 (100*10^(-2)). Similarly, zero instances are not equal if their scale differs.
 public float floatValue() 
    Returns this {@code BigDecimal} as a float value. If {@code this} is too big to be represented as an float, then {@code Float.POSITIVE_INFINITY} or {@code Float.NEGATIVE_INFINITY} is returned.

    Note, that if the unscaled value has more than 24 significant digits, then this decimal cannot be represented exactly in a float variable. In this case the result is rounded.

    For example, if the instance {@code x1 = new BigDecimal("0.1")} cannot be represented exactly as a float, and thus {@code x1.equals(new BigDecimal(x1.folatValue())} returns {@code false} for this case.

    Similarly, if the instance {@code new BigDecimal(16777217)} is converted to a float, the result is {@code 1.6777216E}7.

 public int hashCode() 
    Returns a hash code for this {@code BigDecimal}.
 public int intValue() 
    Returns this {@code BigDecimal} as an int value. Any fractional part is discarded. If the integral part of {@code this} is too big to be represented as an int, then {@code this} % 2^32 is returned.
 public int intValueExact() 
    Returns this {@code BigDecimal} as a int value if it has no fractional part and if its value fits to the int range ([-2^{31}..2^{31}-1]). If these conditions are not met, an {@code ArithmeticException} is thrown.
 public long longValue() 
    Returns this {@code BigDecimal} as an long value. Any fractional part is discarded. If the integral part of {@code this} is too big to be represented as an long, then {@code this} % 2^64 is returned.
 public long longValueExact() 
    Returns this {@code BigDecimal} as a long value if it has no fractional part and if its value fits to the int range ([-2^{63}..2^{63}-1]). If these conditions are not met, an {@code ArithmeticException} is thrown.
 public BigDecimal max(BigDecimal val) 
    Returns the maximum of this {@code BigDecimal} and {@code val}.
 public BigDecimal min(BigDecimal val) 
    Returns the minimum of this {@code BigDecimal} and {@code val}.
 public BigDecimal movePointLeft(int n) 
    Returns a new {@code BigDecimal} instance where the decimal point has been moved {@code n} places to the left. If {@code n < 0} then the decimal point is moved {@code -n} places to the right.

    The result is obtained by changing its scale. If the scale of the result becomes negative, then its precision is increased such that the scale is zero.

    Note, that {@code movePointLeft(0)} returns a result which is mathematically equivalent, but which has {@code scale >= 0}.

 public BigDecimal movePointRight(int n) 
    Returns a new {@code BigDecimal} instance where the decimal point has been moved {@code n} places to the right. If {@code n < 0} then the decimal point is moved {@code -n} places to the left.

    The result is obtained by changing its scale. If the scale of the result becomes negative, then its precision is increased such that the scale is zero.

    Note, that {@code movePointRight(0)} returns a result which is mathematically equivalent, but which has scale >= 0.

 public BigDecimal multiply(BigDecimal multiplicand) 
    Returns a new {@code BigDecimal} whose value is {@code this * multiplicand}. The scale of the result is the sum of the scales of the two arguments.
 public BigDecimal multiply(BigDecimal multiplicand,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this * multiplicand}. The result is rounded according to the passed context {@code mc}.
 public BigDecimal negate() 
    Returns a new {@code BigDecimal} whose value is the {@code -this}. The scale of the result is the same as the scale of this.
 public BigDecimal negate(MathContext mc) 
    Returns a new {@code BigDecimal} whose value is the {@code -this}. The result is rounded according to the passed context {@code mc}.
 public BigDecimal plus() 
    Returns a new {@code BigDecimal} whose value is {@code +this}. The scale of the result is the same as the scale of this.
 public BigDecimal plus(MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code +this}. The result is rounded according to the passed context {@code mc}.
 public BigDecimal pow(int n) 
    Returns a new {@code BigDecimal} whose value is {@code this ^ n}. The scale of the result is {@code n} times the scales of {@code this}.

    {@code x.pow(0)} returns {@code 1}, even if {@code x == 0}.

    Implementation Note: The implementation is based on the ANSI standard X3.274-1996 algorithm.

 public BigDecimal pow(int n,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this ^ n}. The result is rounded according to the passed context {@code mc}.

    Implementation Note: The implementation is based on the ANSI standard X3.274-1996 algorithm.

 public int precision() 
    Returns the precision of this {@code BigDecimal}. The precision is the number of decimal digits used to represent this decimal. It is equivalent to the number of digits of the unscaled value. The precision of {@code 0} is {@code 1} (independent of the scale).
 public BigDecimal remainder(BigDecimal divisor) 
    Returns a new {@code BigDecimal} whose value is {@code this % divisor}.

    The remainder is defined as {@code this - this.divideToIntegralValue(divisor) * divisor}.

 public BigDecimal remainder(BigDecimal divisor,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this % divisor}.

    The remainder is defined as {@code this - this.divideToIntegralValue(divisor) * divisor}.

    The specified rounding mode {@code mc} is used for the division only.

 public BigDecimal round(MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this}, rounded according to the passed context {@code mc}.

    If {@code mc.precision = 0}, then no rounding is performed.

    If {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY}, then an {@code ArithmeticException} is thrown if the result cannot be represented exactly within the given precision.

 public int scale() 
    Returns the scale of this {@code BigDecimal}. The scale is the number of digits behind the decimal point. The value of this {@code BigDecimal} is the unsignedValue * 10^(-scale). If the scale is negative, then this {@code BigDecimal} represents a big integer.
 public BigDecimal scaleByPowerOfTen(int n) 
    Returns a new {@code BigDecimal} whose value is {@code this} 10^{@code n}. The scale of the result is {@code this.scale()} - {@code n}. The precision of the result is the precision of {@code this}.

    This method has the same effect as #movePointRight , except that the precision is not changed.

 public BigDecimal setScale(int newScale) 
    Returns a new {@code BigDecimal} instance with the specified scale. If the new scale is greater than the old scale, then additional zeros are added to the unscaled value. If the new scale is smaller than the old scale, then trailing zeros are removed. If the trailing digits are not zeros then an ArithmeticException is thrown.

    If no exception is thrown, then the following equation holds: {@code x.setScale(s).compareTo(x) == 0}.

 public BigDecimal setScale(int newScale,
    RoundingMode roundingMode) 
    Returns a new {@code BigDecimal} instance with the specified scale.

    If the new scale is greater than the old scale, then additional zeros are added to the unscaled value. In this case no rounding is necessary.

    If the new scale is smaller than the old scale, then trailing digits are removed. If these trailing digits are not zero, then the remaining unscaled value has to be rounded. For this rounding operation the specified rounding mode is used.

 public BigDecimal setScale(int newScale,
    int roundingMode) 
    Returns a new {@code BigDecimal} instance with the specified scale.

    If the new scale is greater than the old scale, then additional zeros are added to the unscaled value. In this case no rounding is necessary.

    If the new scale is smaller than the old scale, then trailing digits are removed. If these trailing digits are not zero, then the remaining unscaled value has to be rounded. For this rounding operation the specified rounding mode is used.

 public short shortValueExact() 
    Returns this {@code BigDecimal} as a short value if it has no fractional part and if its value fits to the short range ([-2^{15}..2^{15}-1]). If these conditions are not met, an {@code ArithmeticException} is thrown.
 public int signum() 
    Returns the sign of this {@code BigDecimal}.
 public BigDecimal stripTrailingZeros() 
    Returns a new {@code BigDecimal} instance with the same value as {@code this} but with a unscaled value where the trailing zeros have been removed. If the unscaled value of {@code this} has n trailing zeros, then the scale and the precision of the result has been reduced by n.
 public BigDecimal subtract(BigDecimal subtrahend) 
    Returns a new {@code BigDecimal} whose value is {@code this - subtrahend}. The scale of the result is the maximum of the scales of the two arguments.
 public BigDecimal subtract(BigDecimal subtrahend,
    MathContext mc) 
    Returns a new {@code BigDecimal} whose value is {@code this - subtrahend}. The result is rounded according to the passed context {@code mc}.
 public BigInteger toBigInteger() 
    Returns this {@code BigDecimal} as a big integer instance. A fractional part is discarded.
 public BigInteger toBigIntegerExact() 
    Returns this {@code BigDecimal} as a big integer instance if it has no fractional part. If this {@code BigDecimal} has a fractional part, i.e. if rounding would be necessary, an {@code ArithmeticException} is thrown.
 public String toEngineeringString() 
    Returns a string representation of this {@code BigDecimal}. This representation always prints all significant digits of this value.

    If the scale is negative or if {@code scale - precision >= 6} then engineering notation is used. Engineering notation is similar to the scientific notation except that the exponent is made to be a multiple of 3 such that the integer part is >= 1 and < 1000.

 public String toPlainString() 
    Returns a string representation of this {@code BigDecimal}. No scientific notation is used. This methods adds zeros where necessary.

    If this string representation is used to create a new instance, this instance is generally not identical to {@code this} as the precision changes.

    {@code x.equals(new BigDecimal(x.toPlainString())} usually returns {@code false}.

    {@code x.compareTo(new BigDecimal(x.toPlainString())} returns {@code 0}.

 public String toString() 
    Returns a canonical string representation of this {@code BigDecimal}. If necessary, scientific notation is used. This representation always prints all significant digits of this value.

    If the scale is negative or if {@code scale - precision >= 6} then scientific notation is used.

 public BigDecimal ulp() 
    Returns the unit in the last place (ULP) of this {@code BigDecimal} instance. An ULP is the distance to the nearest big decimal with the same precision.

    The amount of a rounding error in the evaluation of a floating-point operation is often expressed in ULPs. An error of 1 ULP is often seen as a tolerable error.

    For class {@code BigDecimal}, the ULP of a number is simply 10^(-scale).

    For example, {@code new BigDecimal(0.1).ulp()} returns {@code 1E-55}.

 public BigInteger unscaledValue() 
    Returns the unscaled value (mantissa) of this {@code BigDecimal} instance as a {@code BigInteger}. The unscaled value can be computed as {@code this} 10^(scale).
 public static BigDecimal valueOf(long unscaledVal) 
    Returns a new {@code BigDecimal} instance whose value is equal to {@code unscaledVal}. The scale of the result is {@code 0}, and its unscaled value is {@code unscaledVal}.
 public static BigDecimal valueOf(double val) 
    Returns a new {@code BigDecimal} instance whose value is equal to {@code val}. The new decimal is constructed as if the {@code BigDecimal(String)} constructor is called with an argument which is equal to {@code Double.toString(val)}. For example, {@code valueOf("0.1")} is converted to (unscaled=1, scale=1), although the double {@code 0.1} cannot be represented exactly as a double value. In contrast to that, a new {@code BigDecimal(0.1)} instance has the value {@code 0.1000000000000000055511151231257827021181583404541015625} with an unscaled value {@code 1000000000000000055511151231257827021181583404541015625} and the scale {@code 55}.
 public static BigDecimal valueOf(long unscaledVal,
    int scale) 
    Returns a new {@code BigDecimal} instance whose value is equal to {@code unscaledVal} 10^(-{@code scale}). The scale of the result is {@code scale}, and its unscaled value is {@code unscaledVal}.