四舍五入至最接近的0.05 [英] Rounding Mechanism to nearest 0.05
本文介绍了四舍五入至最接近的0.05的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用php4,5.2及以下版本(而非5.3)来解决舍入机制 目前,我正在进行0.05舍入,类似于此页面:
I would like to solve rounding mechanism by using php4,5.2 and below (not 5.3) Currently I am doing 0.05 rounding, something like this page:
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
我尝试使用字符串将其拆分并手动进行添加,但这并不是一个很好的解决方案,希望在这里可以找到可以解决该问题的人.
I try to use string to split it out and manually do adding, but not really a good solution, hoping here can find someone to solve it.
推荐答案
使用此功能
function rndfunc($x){
return round($x * 2, 1) / 2;
}
这篇关于四舍五入至最接近的0.05的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文