note 86330 modified in function.round by danbrown

From: Date: Mon, 13 Oct 2008 15:18:07 +0000
Subject: note 86330 modified in function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145322@lists.php.net to get a copy of this message
Here is another method to round digits with precision support: <?php function roundDigits( $value, $precision=0 ) { $precisionFactor = ($precision == 0) ? 1 : pow( 10, $precision ); return round( $value * $precisionFactor ) / $precisionFactor; } ?> Example: echo roundDigits(1.859438,2) . "<br />"; // equals 1.86 echo roundDigits(1.444444,4); // equals 1.4444 Greetings, darki --was-- Here is another method to round digits with precision support: function roundDigits( $value, $precision=0 ) { $precisionFactor = ($precision == 0) ? 1 : pow( 10, $precision ); return round( $value * $precisionFactor ) / $precisionFactor; } Example: echo roundDigits(1.859438,2) . "<br />"; // equals 1.86 echo roundDigits(1.444444,4); // equals 1.4444 Greetings, darki http://php.net/manual/en/function.round.php

« previous php.notes (#145322) next »