Page 1 of 1

need a float with 2 decimal places

Posted: Thu Aug 04, 2005 12:30 pm
by nephish
Hey there
i have a variable and i need to make it a float to display later.

i cant use printf() because the value will display text if there is no numeric value

i also cant just set it to a float because i need to have it go to 2 decimal places.

so if $var = 12.3 i will get 12.30
like with money, i dont have .3 dollars, i have 30 cents.
this isnt a money project but the same would apply

lots of docs out there on type conversions, but i couldn't find out how to do this
thanks

Posted: Thu Aug 04, 2005 12:46 pm
by feyd
  1. wrong forum, PHP - Code is where to post this (the thread will be moved shortly)
  2. using a combination of is_numeric() with sprintf() should do it nicely...

Posted: Thu Aug 04, 2005 2:00 pm
by nephish
sorry about that,

and thanks for the tip