如果:
float a = 789.4945f;
我们想让小数点后两位前移,并四舍五入,那么:
int b = (int)Math.round(a * 100); 对于还原小数点后两位:
float c = (double)b / 100.00;
本文介绍如何将一个浮点数的小数点后两位进行四舍五入处理,并提供了具体的代码实现。通过乘以100并使用Math.round()函数进行四舍五入,再除以100还原小数点位置。
如果:
float a = 789.4945f;
我们想让小数点后两位前移,并四舍五入,那么:
int b = (int)Math.round(a * 100); 对于还原小数点后两位:
float c = (double)b / 100.00;
188

被折叠的 条评论
为什么被折叠?