BigDecimal class Methods in Java Part -II

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.

intValueExact()It converts this BigDecimal to an int, checking for lost information.

longValue(): It converts this BigDecimal to a long.

longValueExact()It converts this BigDecimal to a long, checking for lost information.

max() It returns the maximum of this BigDecimal and val.

min()It returns the minimum of this BigDecimal and val.

movePointLeft()It returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.

movePointRight(): It returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.

multiply(BigDecimal)It returns a BigDecimal whose value is (this ×multiplicand), and whose scale is (this.scale() +multiplicand.scale()).

multiply(BigDecimal, MathContext)It returns a BigDecimal whose value is (this ×multiplicand), with rounding according to the context settings.

negate()It returns a BigDecimal whose value is (-this),and whose scale is this.scale().

negate(MathContext)It returns a BigDecimal whose value is (-this), with rounding according to the context settings.

plus()It returns a BigDecimal whose value is (+this), and whose scale is this.scale().

plus(MathContext)It returns a BigDecimal whose value is (+this), with rounding according to the context settings.

pow(int)It returns a BigDecimal whose value is (this^n), The power is computed exactly, to unlimited precision.

pow(int, MathContext): It returns a BigDecimal whose value is (this%^n).

precision()It returns the precision of this BigDecimal.

remainder(BigDecimal)It returns a BigDecimal whose value is (this % divisor).

remainder(BigDecimal, MathContext)It returns a BigDecimal whose value is (this %divisor), with rounding according to the context settings.

round(MathContext)It returns a BigDecimal rounded according to the MathContext settings. 

scale()It returns the scale of this BigDecimal.

Some more Methods BigDecimal class Part -I

Some more Methods BigDecimal class Part -III

No comments:

Post a Comment