-2

我试图在最后一位四舍五入显示一个浮点数,例如:0.123455 将显示为 0.12346,0.123454 将显示为 0.12345。我当前的代码(不能正常工作)如下:

int iFactorSum = 100000;
            int iRoundSum = (int) (fSumatoria * iFactorSum + 0.5);
            fSumatoria = (float) iRoundSum / iFactorSum;

fSumatoria 存储我要转换的数字。谢谢

4

2 回答 2

0

To round up, you can use Math.ceil(numberGrade).

To round to the nearest integer, use Math.round(numberGrade).

See: the Math class

From here.

于 2017-10-30T04:21:58.733 回答
-3

用于Math.round()四舍五入浮点数

https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(double)

于 2017-10-30T04:21:12.963 回答