skeezmo Posted February 26, 2006 Share Posted February 26, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/3638-sprintf/ Share on other sites More sharing options...
Barand Posted February 27, 2006 Share Posted February 27, 2006 [code]$money = 200.00;if (intval($money)==$money) { $val = sprintf('$%d', $money);}else { $val = sprintf('$%01.2f', $money);}echo $val;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3638-sprintf/#findComment-12654 Share on other sites More sharing options...
skeezmo Posted February 27, 2006 Author Share Posted February 27, 2006 thanks Quote Link to comment https://forums.phpfreaks.com/topic/3638-sprintf/#findComment-12655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.