rounding and traling zeros

by "Keith D Sellars" <Keith(at)webgraffix.com>

 Date:  Sat, 12 Apr 2003 17:32:52 -0400
 To:  <hwg-languages(at)hwg.org>
  todo: View Thread, Original
If I have the following in php:
<?
    $x .= .5 * $b * ((($a + (.25 * ($f - 25))) + $d + $e) * (1 + $g));
?>

... and I want the result ($x) to be rounded to 2 digits to the right of the
decimal place, BUT to ALWAYS show 2 digits (for instance, I don't want
$24.50 to show as $24.5,), how would I do that?  I know that I can use:

round($x,2)

to round the result to 2 digits, but how do I ensure that it it shows the
trailing zero if needed?

Also, how do I incorporate the round($x,2) in the above calculation?  Should
I simply create a second line that shows:
$x = round($x,2)
... or will that even work at all?

Many thanks in advance and please excuse my ingorance in asking what may
seem like simple questions.  I may not have the knowledge in my head, but at
least I know where the answers can be found!

Keith D Sellars
WebGraffix
www.webgraffix.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.