如何在 PHP 中四舍五入到最接近的整数小数

How to round down to nearest whole decimal in PHP

不确定我是否正确解释了问题,但下面是一些我需要发生的事情的随机示例

20.39 变为 20.30

40.55 变为 40.50

9.22 变为 9.20

使用floor after multiplying by 10 and then divide by 10 again. To keep the second decimal place after rounding, use number_format.

$values = [20.39,40.55,9.22];
foreach ($values as $value) {
    echo number_format(floor($value * 10) / 10, 2);
}

输出:

20.30
40.50
9.20