Change string to a price

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keveh
Forum Commoner
Posts: 27
Joined: Mon Aug 08, 2005 5:50 am

Change string to a price

Post by keveh »

I am making a calculator for a website, with a starting price then optional extras that a user selects.

So say the price was £11,345 and two extras were selected at £450 and 1,300 your total would be £13, 095.

I have done my calculations just with the numbers, so 11345 + 450 + 1300.

This is where my problem is, as my total would be simply be the number 13095, when I echo it, it wont produce the comma after the first two numbers.

Is there a way that I can take a string and insert a comma after the second character?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

number_format

Just for informational purposes, It should be noted that in germany number format is different. 10.000,56 where comma is the decimal point and thousands separator is a dot.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

money_format() might be of interest too.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Deliberately left money_format out... The following (from the manual for money_format) needs to be noted...
Note: The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Uh yeah, and it seems really complicated as well. Good call Goblin.
Post Reply