如何在Java中将46.565舍入到46.57? (没有天花板)

时间:2013-08-13 08:13:41

标签: java math rounding

我一直在使用Math.round,一切都很好,直到我发现任何以“5”结尾的数字都没有四舍五入。

double roundtotal = Math.round(total * 100.0) / 100.0;

哪一轮到2位小数,但不是46.565到46.57,例如

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

double roundtotal = ((int)((total*100.0)+0.5)) / 100.0;