Hello. There is a number, for example 66241 . How to get a "round" number - 66300 ?
I would be grateful for any useful information.
Hello. There is a number, for example 66241 . How to get a "round" number - 66300 ?
I would be grateful for any useful information.
$number = 66241; $result = (ceil($number/100))*100; Here is the function that rounds, but from 66241 it will not give out 66300, since 41 is closer to the bottom, but 66251 will be 66300
echo round(66251 , -2); For rounding to dozens - you can divide the number by 10, use the rounding function and multiply the result by 10. (56/10 = 5.6 -> 6 -> 6 * 10 = 60) For rounding to hundreds - you can divide the number by 100, use the rounding function and multiply the result by 100. (561/101 = 5.61 -> 6 -> 6 * 100 = 600) For thousands, tens of thousands, etc. similarly. Sorry if your question is not correctly understood.
$numbers = [66241, 15790, 25000]; function round_up($num, $precision) { $num = $num / pow(10, $precision); $num = ceil($num); return $num * pow(10, $precision); } foreach ($numbers as $number) { echo round_up($number, 2) . "\n"; } Result:
66300 15800 25000 Source: https://ru.stackoverflow.com/questions/630239/
All Articles