Android的 - 圆整到小数点后2位 [英] Android - Round to 2 decimal places
本文介绍了Android的 - 圆整到小数点后2位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2808535/round-a-double-to-2-significant-figures-after-decimal-point">Round小数点后双至2显著图
Possible Duplicate:
Round a double to 2 significant figures after decimal point
我知道有一个例子如何圆这种数字工厂。 但可能有人告诉我如何圆形双,得到的价值,我可以显示为 字符串,总是有2位小数?
I know that there is plant of examples 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屋!
查看全文