Page 1 of 1
Help with displaying a float value
Posted: Fri Nov 26, 2004 7:14 am
by DudeBori82
How do I limit the amount of decimal places when using 'echo' to display a float value. (It defaults to three I think, but I want it to display only two.) Please share with me your great wisdom and knowledge.

How bout this
Posted: Fri Nov 26, 2004 7:31 am
by neophyte
Does this help?
Code: Select all
<?php
echo round(5.045, 2); // echos 5.05
?>
Posted: Fri Nov 26, 2004 8:04 am
by DudeBori82
thanx!
Posted: Fri Nov 26, 2004 8:06 am
by phpScott
not echo but if you
Code: Select all
<?php
$unitCost = 12.4456;
sprintf("%01.2f",$unitCost);
?>
will output 12.44