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); // 2 precision

        BigDecimal bg1 = new BigDecimal("100.123");
        BigDecimal bg2 = new BigDecimal("50.56");

        // subtract bg1 with bg2 using mc and assign result to bg3
        BigDecimal bg3 = bg1.subtract(bg2, mc);

        String str = "The Result of Subtraction is " + bg3;

        // print bg3 value
        System.out.println(str);
    }
}