Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在使用 Math.round,一切似乎都很好,直到我注意到任何以“5”结尾的数字都没有四舍五入。
double roundtotal = Math.round(total * 100.0) / 100.0;
例如四舍五入到小数点后 2 位,但不四舍五入 46.565 到 46.57
任何人都可以帮忙吗?
你可以这样做:
double roundtotal = ((int)((total*100.0)+0.5)) / 100.0;