在Java中打印2位小数的Integer [英] Print Integer with 2 decimal places in Java

查看:657
本文介绍了在Java中打印2位小数的Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我使用整数乘以100作为小数(0.1是10等)。你能帮我把格式化输出显示为十进制吗?

解决方案

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆