可能重复:
在PHP 中四舍五入到最接近的五的倍数
我必须把数字四舍五入,但不能用传统的方法。我想四舍五入到5、10、15、20、25、30、35、40、45、50等等。四舍五舍五入后,四舍五进的数字应该降到上面列出的数字之一。
有可能吗?
试试这个:
$rounded_value = round($original_value/5) * 5;
或者如果总是四舍五入:
$rounded_value = floor($original_value/5) * 5;
或者如果总是四舍五入:
$rounded_value = ceil($original_value/5) * 5;
退房http://www.php.net/manual/en/function.round.php#32008
<?php
// Rounding to the nearest fifth
// or any other increment you wish...
$percent = "48";
$num = round($percent/5)*5;
echo $num;
// returns 50
$percentt = "47";
$numm = round($percentt/5)*5;
echo $numm;
// returns 45
?>