note 70941 deleted from function.round by danbrown

From: Date: Sun, 17 May 2009 16:19:13 +0000
Subject: note 70941 deleted from function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154797@lists.php.net to get a copy of this message
Note Submitter: ---- Javascript round_number function roundnumber (n, d) { n = n - 0; if (d == null) d = 2; var f = Math.pow(10, d); n += Math.pow(10, - (d + 1)); n = Math.round(n * f) / f; n += Math.pow(10, - (d + 1)); n += ''; return d == 0 ? n.substring(0, n.indexOf('.')) : n.substring(0, n.indexOf('.') + d + 1); } PHP round_number; function roundnumber($n, $d = 0) { $n = $n - 0; if ($d === NULL) $d = 2; $f = pow(10, $d); $n += pow(10, - ($d + 1)); $n = round($n * $f) / $f; $n += pow(10, - ($d + 1)); $n += ''; if ( $d == 0 ) : return substr($n, 0, strpos($n, '.')); else : return substr($n, 0, strpos($n, '.') + $d + 1); endif; }

« previous php.notes (#154797) next »