BigDecimal class Methods in Java Part -I

java.math.BigDecimal

Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the 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.


Some of the Methods of  StrictMath class.

BigDecimal.abs()This method returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().

BigDecimal.abs(MathContext)This method returns a BigDecimal whose value is the absolute value of this BigDecimal, with rounding according to the context settings.

BigDecimal.add(BigDecimal) This method returns a BigDecimal whose value is (this +augend).

BigDecimal.add(BigDecimal, MathContext)This method returns a BigDecimal whose value is (this + augend), with rounding according to the context settings.

byteValue()This method returns the value of the specified number as a byte.

BigDecimal.byteValueExact()This method converts this BigDecimal to a byte, checking for lost information.

compareTo()This method compares this BigDecimal with the specified BigDecimal.

divide(BigDecimal)This method returns a BigDecimal whose value is (this /divisor).

divide(BigDecimal, MathContext)This method returns a BigDecimal whose value is (this /divisor), with rounding according to the context settings.

divide(BigDecimal, RoundingMode)This method returns a BigDecimal whose value is (this /divisor), and whose scale is this.scale().

divide(BigDecimal, int, RoundingMode)This method returns a BigDecimal whose value is (this /divisor), and whose scale is as specified.

divideAndRemainder(BigDecimal)This method returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of the remainder on the two operands.

divideAndRemainder(BigDecimal, MathContext)This method returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of the remainder on the two operands calculated with rounding according to the context settings.

divideToIntegralValue(BigDecimal)This method returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down.

divideToIntegralValue(BigDecimal ,MathContext)This method returns a BigDecimal whose value is the integer part of (this / divisor).

doubleValue()This method converts this BigDecimal to a double.

equals(Object)This method compares this BigDecimal with the specified Object for equality.

floatValue()This method converts this BigDecimal to a float.

hashCode()This method returns the hash code for this BigDecimal.

intValue()This method converts this BigDecimal to an int.

Some more Methods of BigDecimal class Part -II

Some more Methods of BigDecimal class Part -III

No comments:

Post a Comment