note 124756 deleted from function.round by cmb

From: Date: Tue, 25 Feb 2020 14:55:13 +0000
Subject: note 124756 deleted from function.round by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214224@lists.php.net to get a copy of this message
Note Submitter: Astro ---- Be careful, in some PHP versions and with some conditions round() or number_format() results may be unexpected, e.g. round(1/12, 10). Alternatively you can use something like this: function NumberPrecision($n, $precision=0, $is_round=true) { $r = (($is_round) ? 5 : 1); $n += $r * pow(10, -($precision+1)); $comma = '.'; $n .= $comma; list($n, $frac) = explode($comma, $n, 2); $n = rtrim(rtrim($n, $comma) . $comma . substr($frac, 0, $precision), $comma); return ($n); }

« previous php.notes (#214224) next »