我想通过使用 php4,5.2 及以下(不是 5.3)来解决舍入机制 目前我正在进行 0.05 舍入,类似于此页面:
http://www.bnm.gov.my/index.php?ch=209&pg=657&ac=568
before rounding | after rounding
89.90 | 89.90
89.91 | 89.90
89.92 | 89.90
89.93 | 89.95
89.94 | 89.95
89.95 | 89.95
89.96 | 89.95
89.97 | 89.95
89.98 | 90.00
89.99 | 90.00
我尝试用string拆分出来手动添加,但不是很好的解决方案,希望这里能找到人解决。
最佳答案
使用这个函数
function rndfunc($x){
return round($x * 2, 1) / 2;
}
关于php - 四舍五入机制至最接近的 0.05,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592352/