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("5.46497");

        MathContext mc = new MathContext(3); // 3 precision

        // bg1 is rounded using mc
        BigDecimal bg2 = bg1.round(mc);

        String str = "The value " + bg1 + " after rounding is " + bg2;

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