Example usage for java.math BigDecimal abs

List of usage examples for java.math BigDecimal abs

Introduction

In this page you can find the example usage for java.math BigDecimal abs.

Prototype

public BigDecimal abs(MathContext mc) 

Source Link

Document

Returns a BigDecimal whose value is the absolute value of this BigDecimal , with rounding according to the context settings.

Usage

From source file:Main.java

public static void main(String[] args) {

    MathContext mc = new MathContext(2);
    MathContext mc1 = new MathContext(4);

    BigDecimal bg1 = new BigDecimal("123.1234");

    // assign absolute value of bg1 to bg2 rounded to 2 precision using mc
    BigDecimal bg2 = bg1.abs(mc);

    // assign absolute value of bg1 to bg3 rounded to 4 precision using mc1
    BigDecimal bg3 = bg1.abs(mc1);

    System.out.println(bg2);/*from   ww  w .java 2  s . c o m*/
    System.out.println(bg3);
}