Jump to content


commas in numbers

  • Please log in to reply
2 replies to this topic

#1 Braet

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 August 2006 - 06:19 AM

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:

$numb2 = str_replace(",", "", $numb);

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

#2 GingerRobot

  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 20 August 2006 - 08:41 AM

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


#3 Braet

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 August 2006 - 10:48 AM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users