![]() |
VOOZH | about |
public BigDecimal abs()Parameters: The method does not accept any parameters. Return Value: Returns a BigDecimal whose value is the absolute value of this BigDecimal scale is this.scale(). Below programs will illustrate the use of java.math.BigDecimal.abs() method : Program 1
Absolute value is 51
Absolute value is 63.93471
public BigDecimal abs(MathContext mc)Parameters : The function accepts only one parameter mc of MathContext class object, which specifies precision settings to be used for rounding off the BigDecimal. Return Value: Returns a BigDecimal whose value is the absolute value of this BigDecimal obtained by rounding it off according to the precision settings specified by the object mc. Exception : The method throws an ArithmeticException, if the result is inexact but the rounding mode is UNNECESSARY. Below programs illustrate the use of java.math.BigDecimal.abs() method with specified MathContext : Program 1
Absolute value, rounded to 2 precision is 52
Absolute value, rounded to 15 precision is 143567812363.935