double dTmp = 1.234;
int tenths = ((int)(dTmp * 10)) % 10;//十分位
int percentile = ((int)(dTmp * 100)) % 10;//百分位
/* 整数部分 + 小数点后一位 + 小数点后两位四舍五入 */
double res = (int)dTmp + (double)(tenths) / 10 + (percentile >= 5 ? 0.1 : 0);
06-25
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交