Java.math Package-BigDecimal Class Java.math.BigDecimal.abs() Method - Java.math Package

What is Java math BigDecimal abs() Method?


The java.math.BigDecimal.abs(MathContext mc) returns a BigDecimal whose price is the absolute price of this BigDecimal, with rounding according to the context settings.


Following is the declaration for java.math.BigDecimal.abs() method.


mc − The context to use.

Return Value

This method returns the absolute value of the called value i.e abs(this), rounded as necessary.


Arithmetic Exception − If the result is inexact but the rounding mode is UNNECESSARY.


The following example shows the usage of math.BigDecimal.abs() method.

Let us compile and run the above program, this will produce the following result −

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Java.math Package Topics