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) {

        BigDecimal bg1 = new BigDecimal("12.345");
        BigDecimal bg2 = new BigDecimal("23.456");

        System.out.println("Object Value is " + bg1);
        System.out.println("Augend value is " + bg2);

        // create MathContext object with 4 precision
        MathContext mc = new MathContext(4);

        // perform add operation on bg1 with augend bg2 and context mc
        BigDecimal bg3 = bg1.add(bg2, mc);

        System.out.println("Result is " + bg3);
    }
}