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

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

问题描述

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

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位小数的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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