Jump to content


Photo

sprintf


  • Please log in to reply
2 replies to this topic

#1 skeezmo

skeezmo
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPhoenix!

Posted 26 February 2006 - 08:08 PM

I have found on php.net, that sprintf("%01.2f", $money); 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?
Skeezmo



The truth about Windows Programming: Windoze M.E. More Errors

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 27 February 2006 - 12:28 AM

$money = 200.00;

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 skeezmo

skeezmo
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationPhoenix!

Posted 27 February 2006 - 01:05 AM

thanks
Skeezmo



The truth about Windows Programming: Windoze M.E. More Errors




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users