Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Rounding up 10

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?

• PHP Code:
``` \$number = 3; \$rounded = ceil(\$number/10)*10; //\$rounded=10;  ```

• PHP Code:
``` \$var = 102;echo round(\$var, -1);  ```

• We have a winner (actual output from the equations in the posts) -
Code:
```Gjay's -
3 = 10
107 = 110
102 = 110
100 = 100
94 = 100

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

• Of course, mine rounds and not rounds up

What I was thinking of (but didn't type) was:
PHP Code:
``` \$var = 102;echo round(\$var + 5, -1);  ```

• Thanks for all your help. Ive got my script all working now.

• Originally Posted by PappaJohn
Of course, mine rounds and not rounds up

What I was thinking of (but didn't type) was:
PHP Code:
``` \$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:
PHP Code:
``` \$var = 100; echo round(\$var + 5,-1); // output = 110;  ```

• You're absolutely right.

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•