Java BigDecimal.abs()

Syntax

BigDecimal.abs() has the following syntax.

public BigDecimal abs()

Example

In the following code shows how to use BigDecimal.abs() method.


//from w w w  .  j a v a2s . c  o  m
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    // assign value to bg1
    BigDecimal bg1 = new BigDecimal("-40");

    // value before applying abs
    System.out.println("Value is " + bg1);

    // assign absolute value of bg1 to bg2
    BigDecimal bg2 = bg1.abs();

    // print bg2 value
    System.out.println("Absolute value is " + bg2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger