Java四舍五入取巧方式

来源:互联网 发布:安卓手机网络修复工具 编辑:程序博客网 时间:2024/05/22 11:30

Math.round(A * Math.pow(10, i)) /Math.pow(10, i);


A表示待四舍五入的数字


i表示保留小数点几位数


其中Math.pow(10, i)表示10的i次方


例如:

Math.round(14.235568941 * Math.pow(10, 2)) /Math.pow(10, 2);

结果:14.24

Math.round(14.234568941 * Math.pow(10, 2)) /Math.pow(10, 2);

结果:14.23

0 0
原创粉丝点击