java - remove trailing zeros from double (while printing)
Java[Edit]
+
0
-
0
Java - remove trailing zeros from double (while printing)
1 2 3 4 5 6 7// import java.text.DecimalFormat; DecimalFormat format = new DecimalFormat("0.#################"); System.out.println(format.format(0.0)); // 0 System.out.println(format.format(1.0)); // 1 System.out.println(format.format(2.0)); // 2
[Edit]
+
0
-
0
Java - remove trailing zeros from double (while printing)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21import java.text.DecimalFormat; public class Program { public static void main(String[] args) { DecimalFormat format = new DecimalFormat("0.#################"); System.out.println(format.format(0.0)); // 0 System.out.println(format.format(1.0)); // 1 System.out.println(format.format(2.0)); // 2 System.out.println(format.format(3)); // 3 System.out.println(format.format(3.1)); // 3.1 System.out.println(format.format(3.15)); // 3.15 System.out.println(format.format(3.00)); // 3 System.out.println(format.format(3.10)); // 3.1 System.out.println(format.format(3.15)); // 3.15 } }