Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.math.BigDecimal;
import java.math.MathContext;

public class Main {

    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);
        System.out.println(bg3);
    }
}