header
 
     
 
pixel
pixel pixel

Display currency in correct format

If you need to display numbers in the correct currency format (eg - two decimal places $23.34), use the PHP function number_format:
echo number_format($total, 2, '.', ',');

Unhelpful Helpful Rating 4.0 (score out of 5, no. of ratings: 89)
Comments
Comment by Mike on 2005-10-22
I was overthinking this task. Nice snippet and thanks.

Comment by Harry Duvauchelle on 2005-03-09
Excellent! I looked and could not find this simple one line code.

Comment by hermes on 2005-05-02
you might want to put the $ before it though...as the way it's currently written it will just output 9,999.99 instead of $9,999.99 so: echo "$".number_format($total, 2, '.', ','); where $total is the variable you want to format.

Comment by Ruben on 2005-06-16
Very Usefull, just what i'm looking for. Thanks!!

Comment by Judi on 2005-08-17
Thanks, I couldn't seem to find a simple solution anywhere else!

Comment by shahid on 2005-08-25
very usefull in account based reporting

Comment by kamal on 2005-10-08
working on currency values, this realy help me. thanks kamal.

Comment by Brian Robinson on 2006-01-13
to display currency with parentheses when the number is negative and the dollar sign within the parenthesis you can use: setlocale(LC_MONETARY, 'en_US'); money_format('%(#0n',$total)

Comment by KidRPSTL on 2006-03-29
This solved a problem I was having with an application, but only after I read the accompanying comments.

Comment by Herman Player on 2007-07-10
Thank you. I used this to add the total monetary amounts out of mysql column that I have stored as decimal(10,2)

Comment by Englin on 2007-09-11
Thank you.

Comment by Farouk on 2007-11-13
This saved me alot of headaches. thanx

Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image