Jump to content

Archived

This topic is now archived and is closed to further replies.

skeezmo

sprintf

Recommended Posts

I have found on php.net, [b]that sprintf("%01.2f", $money);[/b] will echon out to decimal place holders for currency. What I am looking for is for this to only take place if in the database there happen to be cents attached to the dollar. Otherwise, it just stays the same (no decimals).

Does anyone know how I'd achieve this?

Share this post


Link to post
Share on other sites
[code]$money = 200.00;

if (intval($money)==$money) {
    $val = sprintf('$%d', $money);
}
else {
    $val = sprintf('$%01.2f', $money);
}
echo $val;[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.