...

View Full Version : Resolved displaying dollars and cents



aslum
09-10-2009, 09:42 PM
Is there a PHP function to display a variable to two decimal places?
EG if $price="3.5" I still want it to display as "3.50".

angst
09-10-2009, 09:50 PM
yes,



number_format(3.5,2);

aslum
09-10-2009, 09:58 PM
Thanks! I knew there had to be a function to do it.
You can also do:
number_format($price,"2",".",",")
if you want commas at the thousands/millions/etc.

angst
09-10-2009, 10:02 PM
your welcome!
it will automatically add in commas where needed without the extra arguments.

Fou-Lu
09-11-2009, 05:27 AM
money_format() (http://php.ca/manual/en/function.money-format.php)
Uses more memory and time, but will adhere to the setlocal value if you want to change the currency.

bacterozoid
09-11-2009, 02:23 PM
money_format() only works on linux servers. You're most likely on one, but keep that in mind if you use it.

Jahren
09-11-2009, 04:26 PM
php can do anything ;D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum