|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
How do I take a number as an integer and turn it into a price?
Hello, and thanks for taking some time to read about my PHP problem.
Basically I would like to make some numbers from an integer look like: 1,000,000 (or £1,000,000) instead of 1000000.0000 for price purposes. I found this $formatted = sprintf("%01.0f", $money); which is cool because it removes the four useless zero's, but doesn't add the comma. Any help would be apreciated. THanks. |
|
#2
|
||||
|
||||
|
It's possible there's already a native function that handles this (if so, I'm not familiar with it), but if not, I'd do something like split $formatted on dots, iterate over the characters in the first element, adding a comma after every third element, reversing, and reattaching to the second element of the original array.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
thanks for replying.
how would i do that? (sorry) |
|
#4
|
|||
|
|||
|
just found this
http://uk.php.net/manual/en/function.number-format.php which works perfectly! WOOHOO! thanks |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > How do I take a number as an integer and turn it into a price? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|