I am trying to figure out how to force 2 decimal points. I have been using, ie. $a=round($b+$c,2). The problem is when I go to echo them out print"<tr "bgcolor=\"#ffffce\"><td>$a</td> I can end up with something like 9.1 instead of 9.10. how can I fource the 2 decimal places. I hope that makes some sense.
$a = sprintf("%.2d", $b+$c);
Note that sprintf returns a string, so $a is a string, not a number.
Diego
Thank you Diego, is there an equivalent for numbers?
Jeff
Diego,
In addition where I use this:
<?php $a=67.093333; $b=sprintf("%.2d",$a); echo $b; ?>
it returns 67 and not 67.09 does it work correctly for you?
Sorry, instead of 'd' use 'f'.
http://www.php.net/manual/en/function.sprintf.php