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

What is Java math BigDecimal abs() Method?

Description

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.

Declaration

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

Parameters

mc − The context to use.

Return Value

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

Exception

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

Example

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 DMCA.com Protection Status

Java.math Package Topics