tags:

views:

87

answers:

5

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!

+2  A: 
$num = round($num/10)*10;

(divide by 10 -> 9.3; round -> 9; multiply by 10 -> 90)

Or even simpler:

$num = round($num, -1);
jtbandes
+1  A: 

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);
Bang Dao
+5  A: 

You can use the round function:

round(93, -1, PHP_ROUND_HALF_UP); //90
round(95, -1, PHP_ROUND_HALF_UP); //100
KLee1
The last argument is unneeded. (See my answer for the short method)
jtbandes
+5  A: 

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
jake33
thanks for the help! i got it! many thanks!
devzone
Your welcome :) (By the way, you should start accepting answers to your questions - this will make your "accept rate" go up and it will show which post answered your question.)
jake33
+4  A: 

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.

Nishant Shrivastava
Thanks Great answer
Pankaj Mishra