...

View Full Version : Rounding up 10



Andy92
07-04-2007, 07:49 PM
Hi there,

How can i round a number up to 10? Not the nearest 10. So...

If i had 3, it would round to 10.

And if i have 107, it would go to 110.

And if i had 102 it would go to 110.

And if i had 100 it would stay at 100.

And if i had 94 it would go to 100.

How can i do this?

GJay
07-04-2007, 07:55 PM
$number = 3;
$rounded = ceil($number/10)*10;
//$rounded=10;

PappaJohn
07-04-2007, 07:56 PM
$var = 102;

echo round($var, -1);

CFMaBiSmAd
07-04-2007, 08:56 PM
We have a winner (actual output from the equations in the posts) -


Gjay's -
3 = 10
107 = 110
102 = 110
100 = 100
94 = 100

PappaJohn's -
3 = 0
107 = 110
102 = 100
100 = 100
94 = 90

PappaJohn
07-05-2007, 12:15 AM
Of course, mine rounds and not rounds up

What I was thinking of (but didn't type) was:


$var = 102;

echo round($var + 5, -1);

Andy92
07-05-2007, 12:20 AM
Thanks for all your help. Ive got my script all working now.

Added to all of your reputation! :thumbsup:

GJay
07-05-2007, 08:05 AM
Of course, mine rounds and not rounds up

What I was thinking of (but didn't type) was:


$var = 102;

echo round($var + 5, -1);


if $var is a multiple of 10, then your code will round it up to the next multiple:


$var = 100;
echo round($var + 5,-1);
// output = 110;

PappaJohn
07-05-2007, 03:16 PM
You're absolutely right.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum