nscherneck Posted August 15, 2007 Share Posted August 15, 2007 Hey everyone, First post here. Im trying to echo the result of a mathematical calculation and would like to round it to the hundredths. Heres what ive got... <form id="FormName" action="" method="get" name="FormName"> <p>Unit Name: <input type="text" name="UnitName" size="24"></p> <p>Unit CFM rating: <input type="text" name="CFMRating" size="24"></p> <p>Duct Diameter (at detector location): <input type="text" name="Diameter" size="24"></p> <input type="submit" name="submit"> </form> <?php if ($Diameter > 0) $Radius = ($Diameter / 2); $SquareInch = ($Radius * $Radius * 3.14); $SquareFeet = ($SquareInch / 144); $FPM = ($CFMRating / $SquareFeet); echo "<p>At the detector location the duct is <b>$SquareInch</b> square inches, or <b>$SquareFeet</b> square feet.</p> <p>The air velocity at the detector location is <b>$FPM</b> Feet Per Minute (FPM).</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/ Share on other sites More sharing options...
willpower Posted August 15, 2007 Share Posted August 15, 2007 look up, floor, ceil and number_format in the php manual Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-325194 Share on other sites More sharing options...
AndyB Posted August 15, 2007 Share Posted August 15, 2007 Round - http://ca.php.net/manual/en/function.round.php $rounded = round($var,2);// rounds $var 2 decimal places Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-325216 Share on other sites More sharing options...
Barand Posted August 15, 2007 Share Posted August 15, 2007 Willpower, floor, ceil round to whole numbers - no decimals - not to a specified number of decimal places Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-325232 Share on other sites More sharing options...
tibberous Posted August 16, 2007 Share Posted August 16, 2007 You can still use ceil. echo ceil(($num-.5)*100)/100; How everyone cool does it. Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-325384 Share on other sites More sharing options...
AndyB Posted August 17, 2007 Share Posted August 17, 2007 You can still use ceil. echo ceil(($num-.5)*100)/100; How everyone cool does it. Only if wrong is cool round() is the best function for rounding. Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-326571 Share on other sites More sharing options...
nscherneck Posted August 18, 2007 Author Share Posted August 18, 2007 excellent, thank you everyone! Quote Link to comment https://forums.phpfreaks.com/topic/65143-solved-how-can-i-round-to-the-hundreths-in-a-decimal/#findComment-327800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.