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)); } } /* Rounded number = 12345.679 Rounded number = 12345.679 */