问题
I have the number 1543, I want to make sure that I find the number closest to 1543 which is counted every 100. For eg:
1527 = 1500
1563 = 1600
12034 = 12000
12081 = 12100
I hope that you understand.
回答1:
Use the round() function with a precision value of -2
,
round( $number, -2);
Codepad Viper Demo.
回答2:
you can do that by dividing the number by 100 and using the round function.
回答3:
<?php
function foo($number, $d)
{
return round($number / $d) * $d;
}
echo foo(1527, 100) . "\n";
echo foo(12081, 100) . "\n";
?>
来源:https://stackoverflow.com/questions/14935390/convert-adjust-number-in-a-specific-counting-with-php