php - 四舍五入机制至最接近的 0.05

标签 php rounding

我想通过使用 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/

相关文章:

php - jQuery load() 在不同选项卡上时

c - IEEE 754 : sqrtf() with fesetround(): different results between compilers: 0x42440a72 vs. 0x42440a73

sql - 我如何四舍五入到一个完整的整数postgres

c - 为什么没有返回 int 的 round() 类型的函数?

java - 使用 BigDecimal 数字进行四舍五入

php - 持续更新php页面

php - 使用数据库存储 session 时的 session cookie参数

php - 找出我将在移动设备上的哪些页面

php - ZF2 - 自动加载器类映射 fatal error 'Map file provided does not exist'

php - 去掉小数位而不舍入值