在Java中打印2位小数的Integer [英] Print Integer with 2 decimal places in Java
本文介绍了在Java中打印2位小数的Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
int x = 100;
DecimalFormat df = new DecimalFormat(#。00); //在这里设置你想要的格式。
System.out.println(df.format(x / 100.0));
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?
解决方案
int x = 100;
DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here.
System.out.println(df.format(x/100.0));
这篇关于在Java中打印2位小数的Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文