如何让float变量精确到小数点后两位

2025-05-23 21:17:38
推荐回答(1个)
回答(1):

一个double或者float变量x四舍五入取整,可以(int)(x+0.5);
同理,如果要保留
小数点
后两位
(int)(100*x+0.5)
*
0.01
;