搜索函数 ro round numbers to the nearest multiple of 5
22 -> 20
23 -> 25
40 -> 40
46 -> 45
48 -> 50
等等。
试过这个总是返回更高的值:
5 * ceil($n / 5);
最佳答案
使用 round()
而不是 ceil()
。
5 * round($n / 5);
ceil()
按顺序将 float 向上舍入为下一个整数。 round()
将使用标准舍入规则舍入到最接近的整数。
关于php - 在 PHP 中将整数舍入到最接近的 5 的倍数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12913353/