- Java.math package classes
- Java.math - Home
- Java.math - BigDecimal
- Java.math - BigInteger
- Java.math - MathContext
- Java.math package extras
- Java.math - Enumerations
- Java.math - Discussion
Java.math.BigDecimal.abs() Method
Description
The java.math.BigDecimal.abs() returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().
Declaration
Following is the declaration for java.math.BigDecimal.abs() method.
public BigDecimal abs()
Parameters
NA
Return Value
This method returns the absolute value of the called value i.e abs(this).
Exception
NA
Example
The following example shows the usage of math.BigDecimal.abs() method.
package com.tutorialspoint; import java.math.*; public class BigDecimalDemo { public static void main(String[] args) { // create 2 BigDecimal objects BigDecimal bg1, bg2; // assign value to bg1 bg1 = new BigDecimal("-40"); // value before applying abs System.out.println("Value is " + bg1); // assign absolute value of bg1 to bg2 bg2 = bg1.abs(); // print bg2 value System.out.println("Absolute value is " + bg2); } }
Let us compile and run the above program, this will produce the following result −
Value is -40 Absolute value is 40
java_math_bigdecimal.htm
Advertisements