Page 1 of 1

Rounding number question? PLEASE HELP!

Posted: Wed Sep 17, 2008 1:26 pm
by mapperkids
Hi,

I try to do the rounding as follow, some of numbers is working but some are not.

Original value : 5299792.155 and it show 5.3 after the following statement, but what I want is show as 5300 round up to 1000's

$rounded = substr(round($value['SUM(sales)'], -3), 0, -3); if ($rounded == 0) { echo "0"; } else { echo $rounded; }

Any idea

Thanks!

Re: Rounding number question? PLEASE HELP!

Posted: Wed Sep 17, 2008 1:40 pm
by jaoudestudios
try number_format, I think it will do all of it for you.

Re: Rounding number question? PLEASE HELP!

Posted: Wed Sep 17, 2008 2:35 pm
by mapperkids
jaoudestudios wrote:try number_format, I think it will do all of it for you.
thanks,

but how can I turn the 553235 become 553 (show by 1000s) only using number_format?

Thanks!

Re: Rounding number question? PLEASE HELP!

Posted: Wed Sep 17, 2008 2:37 pm
by jaoudestudios
Not sure why you would do that as you loose information, but you can divide it by 1000
i.e. 553235 / 1000

Re: Rounding number question? PLEASE HELP!

Posted: Wed Sep 17, 2008 6:25 pm
by josh
Divide by your denominator and then use floor(), ceil() or number_format().. or a combination thereof