Page 1 of 1

Change string to a price

Posted: Tue Jan 30, 2007 5:49 am
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?

Posted: Tue Jan 30, 2007 6:01 am
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.

Posted: Tue Jan 30, 2007 7:05 am
by Ollie Saunders
money_format() might be of interest too.

Posted: Tue Jan 30, 2007 7:17 am
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.

Posted: Tue Jan 30, 2007 7:34 am
by Ollie Saunders
Uh yeah, and it seems really complicated as well. Good call Goblin.