note 70941 added to function.round
| From: | php-general at lists dot php dot net | Date: | Sun, 05 Nov 2006 13:31:55 +0000 |
| Subject: | note 70941 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119406@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 66.163.161.117
Probable Submitter: 89.228.130.55
----
Manual Page -- http://www.php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/70941
Del: integrated -- https://master.php.net/note/delete/70941/integrated
Del: useless -- https://master.php.net/note/delete/70941/useless
Del: bad code -- https://master.php.net/note/delete/70941/bad+code
Del: spam -- https://master.php.net/note/delete/70941/spam
Del: non-english -- https://master.php.net/note/delete/70941/non-english
Del: in docs -- https://master.php.net/note/delete/70941/in+docs
Del: other reasons-- https://master.php.net/note/delete/70941
Reject -- https://master.php.net/note/reject/70941
Search -- https://master.php.net/manage/user-notes.php