note 33178 modified in function.round by danbrown

From: Date: Sun, 17 May 2009 16:25:40 +0000
Subject: note 33178 modified in function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154824@lists.php.net to get a copy of this message
The function below regards a higher number of digits for rounding as the number of digits you want to round! At least it rounds a Value to the number of digits you want to: <?php function MyRound($iValue, $iDigits, $iPrecision){ $iDigits = intval($iDigits); $iPrecision = intval($iPrecision); if($iDigits > $iPrecision){ $iPrecision = $iDigits; } for($i = $iPrecision; $i >= $iDigits; $i--){ $iValue = round($iValue, $i); } // for($i = $iPrecision; $i >= $iDigits; $i--) -- END return $iValue; } ?> --was-- The function below regards a higher number of digits for rounding as the number of digits you want to round! At least it rounds a Value to the number of digits you want to: function MyRound($iValue, $iDigits, $iPrecision){ $iDigits = intval($iDigits); $iPrecision = intval($iPrecision); if($iDigits > $iPrecision){ $iPrecision = $iDigits; } for($i = $iPrecision; $i >= $iDigits; $i--){ $iValue = round($iValue, $i); } // for($i = $iPrecision; $i >= $iDigits; $i--) -- END return $iValue; } http://php.net/manual/en/function.round.php

« previous php.notes (#154824) next »