Android - 舍入2位小数 [英] Android - Round to 2 decimal places

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

问题描述


可能重复:

将小数点后的一个双数转换为两个有效数字

我知道有很多关于如何舍弃这种数字的例子。
但是有人可以告诉我如何舍入双倍,得到的值可以显示为
String,并且总是有2个小数位?

I know that there are plenty of examples on how to round this kind numbers. But could someone show me how to round double, to get value that I can display as a String and ALWAYS have 2 decimal places?

推荐答案

您可以使用 String.format(%。2f,d),双击将自动舍入。

You can use String.format("%.2f", d), your double will be rounded automatically.

这篇关于Android - 舍入2位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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