need a float with 2 decimal places

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nephish
Forum Newbie
Posts: 10
Joined: Tue Aug 02, 2005 7:23 pm

need a float with 2 decimal places

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
nephish
Forum Newbie
Posts: 10
Joined: Tue Aug 02, 2005 7:23 pm

Post by nephish »

sorry about that,

and thanks for the tip
Post Reply