Jump to content

Archived

This topic is now archived and is closed to further replies.

Braet

commas in numbers

Recommended Posts

I have a preg_match_all going through some information I submit by form, and pulling out numbers.  These numbers are often in the millions therefore have commas in them.  When I would add them, it would add each section, ie:

123,456,789 +123,456,789 would = 2736 instead of the actual 246,913,578

So I stripped the commas:

[code]$numb2 = str_replace(",", "", $numb);[/code]

Now it adds properly (yaay), but is very hard to read w/out those commas which brings me to my question, any tutorial that you can point me to (as my searches have yeilded nothing and "the" php manual is still confusing to this php newb) that will explain how to treat numbers with commas or a simple fix to either keep those commas and have it add from the array properly or to put the commas back in once the addition is done?

tia yet again
-Brae

Share this post


Link to post
Share on other sites
The number_format() function is your friend here, you can use it show 1000 separators, specify the number of decimal places and the synbol used to show a decimal place

http://uk.php.net/number_format

Share this post


Link to post
Share on other sites
bingo!  ty - driving me mad and have been googling for days - that is (once I figured out how to properly use it) exactly what I needed there.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.