double value = 12345.67890123456; for (int decimals = 0; decimals <= 10; decimals++) { String output = String.format("%." + decimals + "f", value); System.out.println(output); }