Rounding number question? PLEASE HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mapperkids
Forum Newbie
Posts: 15
Joined: Mon Feb 11, 2008 8:53 pm

Rounding number question? PLEASE HELP!

Post 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!
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Rounding number question? PLEASE HELP!

Post by jaoudestudios »

try number_format, I think it will do all of it for you.
mapperkids
Forum Newbie
Posts: 15
Joined: Mon Feb 11, 2008 8:53 pm

Re: Rounding number question? PLEASE HELP!

Post 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!
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Rounding number question? PLEASE HELP!

Post by jaoudestudios »

Not sure why you would do that as you loose information, but you can divide it by 1000
i.e. 553235 / 1000
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Rounding number question? PLEASE HELP!

Post by josh »

Divide by your denominator and then use floor(), ceil() or number_format().. or a combination thereof
Post Reply