I have a data like
93 i want if to become 90
95 i want to become 100
How can I do that in PHP?
Thanks!
I have a data like
93 i want if to become 90
95 i want to become 100
How can I do that in PHP?
Thanks!
$num = round($num/10)*10;
(divide by 10 -> 9.3; round -> 9; multiply by 10 -> 90)
Or even simpler:
$num = round($num, -1);
I think this function should do
ceil
Reference http://php.net/manual/en/function.ceil.php Then it will be like this
10* ceil($number / 10);
You can use the round function:
round(93, -1, PHP_ROUND_HALF_UP); //90
round(95, -1, PHP_ROUND_HALF_UP); //100
You can use PHP's round function and specify -1 as the precision (second parameter), which specifies the number of digits to round to (negative since we're going backwards from the decimal point):
echo round(93, -1); // 90
echo round(95, -1); // 100
Yeah.The answer is same from my side too,you can easily make this happen by using CEIL function which will give the upper value of whatever logic you imply under it.
10* ceil($number / 10);
And as jtbandes has used round function which is also a good solution too.