Best way to get a dollar format

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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Best way to get a dollar format

Post by Burrito »

I need to format some varchars in a dollar format and have been using

Code: Select all

$<?=number_format($amount, 2, '.', '');?>
which has worked beautifully until this morning when I entered a value on my db of 20,000.00. It displays as $20.00 which obviously isn't right.

is there some built in function in php (like in cold fusion) for a dollar format? Or should I be using something different to format my varchars as dollar amounts?

What I don't want to do is force my numberformat to use more place holders and have something like $00020.00 for twenty dollars. Or the alternative, $20.00000 for twenty dollars.

please advise,

thx,

Burrito
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's very likely the comma is at fault if it was in your posted text. Use str_replace() to remove it.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

indeed it was...now though, how can I add the comma back in when I display it?

$20000.00 doesn't look as nice as $20,000.00

thx again pie man...

Burr
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

echo '$' . number_format($value, 2);
should work.
Post Reply