PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old August 19th, 2004, 10:15 AM
foxache foxache is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 7 foxache User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old August 19th, 2004, 10:22 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old August 19th, 2004, 10:27 AM
foxache foxache is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 7 foxache User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks for replying.

how would i do that? (sorry)

Reply With Quote
  #4  
Old August 19th, 2004, 10:33 AM
foxache foxache is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 7 foxache User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
just found this

http://uk.php.net/manual/en/function.number-format.php

which works perfectly!

WOOHOO!
thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How do I take a number as an integer and turn it into a price?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway