Page 1 of 1

Best way to get a dollar format

Posted: Thu Jan 13, 2005 11:02 am
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

Posted: Thu Jan 13, 2005 11:07 am
by feyd
it's very likely the comma is at fault if it was in your posted text. Use str_replace() to remove it.

Posted: Thu Jan 13, 2005 11:16 am
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

Posted: Thu Jan 13, 2005 11:26 am
by feyd

Code: Select all

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