0

After converting currencies I end up with the numbers below:

3628, 5987 and 2359.

I'd like to round them up so they would appear as 3630, 5990 and 2360.

What is the best approach to accomplish this?

My idea of doing this is adding a 0. in front of the number to achieve 0.3628, then using round(0.3628, 3) so that I would get 0.363 and then finally id have to remove 0. and add another zero at the end to achieve 0.3630.

There must be a better way to do it.

Nikk
  • 7,384
  • 8
  • 44
  • 90
  • Your method only works if the original number is 4 digits long. It won't round 28 to 30, it will round it to 2800. – Barmar Aug 10 '16 at 23:23

1 Answers1

3

Like so:

echo ceil(5987 / 10) * 10;

outputs 5990

Robert
  • 10,126
  • 19
  • 78
  • 130
  • Would this also work for 3 digit numbers? And number longer than 4 digits? – Nikk Aug 10 '16 at 23:28
  • 2
    It works for any number: Your value gets devided by 10 and rounded up. Muliplying the result by 10 always gives you the number you started out with rounded up to the next tenner – Stefan Dochow Aug 10 '16 at 23:40