Print Integer with 2 decimal places in Java

user1749458 picture user1749458 · Oct 20, 2012 · Viewed 62.7k times · Source

in my code i use integers multiplied by 100 as decimals (0.1 is 10 etc). Can you help me to format output to show it as decimal?

Answer

Juvanis picture Juvanis · Oct 20, 2012
int x = 100;
DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here.
System.out.println(df.format(x/100.0));