Android的 - 圆整到小数点后2位小数点、Android

2023-09-04 04:34:05 作者:少年的泪不及海水蓝

可能重复:   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.

 
精彩推荐
图片推荐