Borsn Borsn - 3 months ago 21
PHP Question

php Rounding up numbers (3628 > 3630)

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.

Answer

Like so:

echo ceil(5987 / 10) * 10;

outputs 5990

Comments