Jump to content


Photo

Exploding a string & adding commas.


  • Please log in to reply
2 replies to this topic

#1 Cruisecar

Cruisecar
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 April 2006 - 04:55 PM

Hey,

Firstly thank you for reading this, my problem is a very simple one, yet it seems to be very hard for me to achieve the needed result.

Basicly, I have a string ($money) pulled from a database, it could be any value from 0 or more. I need to add commas into that string every 3 numbers - it must be added from the end to the begining.

$money = "1000000"

After going through the function it should be "1,000,000". I tried using explode, and attempted using a wildcard - but there is none, also it would make the number "100,000,0".

I hope someone can help me! And once again, thankyou for reading.

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 26 April 2006 - 05:01 PM

Try
$formatted = number_format($money,2);

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 Cruisecar

Cruisecar
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 April 2006 - 05:06 PM

Thanks for your fast reply, worked a charm! I will definutely visit here more often.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users