Establishing precision of a number..

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
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Establishing precision of a number..

Post by kyoru »

I'm not sure how to tackle this and i've searched through the php functions.
I'm trying to get a number displayed to the nearest 2 decial places so 0.01.
Now, most of the time the trailing digits are zeros, so i tried round($number,2) that didnt work...
and i also tried floor but that didnt do anything either. I tried casting the type to float, and still no effect,
and i also searched and tried round($number/0.01)*0.01 with no effect, i'm guessing the 0's are causing some issues here, is there a way to set the precision of a number? Thank you!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if the trailing digits are zeros they aren't printed by php because it's not a logical display format.

sprintf('%.2f',round($num,2))
Post Reply