Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.DecimalFormat;

public class Main {

    public static void main(String[] args) {
        double numberToRound = 12345.6789;

        DecimalFormat df = new DecimalFormat("0.000");
        System.out.println("Rounded number = " + df.format(numberToRound));

        System.out.println(String.format("Rounded number = %.3f", numberToRound));

    }
}