Print an integer with 2 decimal places in Java
•
Java
In my code, I use integers multiplied by 100 as decimals (0.1 is 10, etc.) Can you format the output for me to display as decimal?
Solution
int x = 100;
int x = 100; DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here. System.out.println(df.format(x/100.0));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码