note 124756 added to function.round

From: Date: Tue, 25 Feb 2020 12:53:38 +0000
Subject: note 124756 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-214220@lists.php.net to get a copy of this message
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); } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 46.63.38.5) ---- Manual Page -- http://php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/124756 Del: integrated -- https://master.php.net/note/delete/124756/integrated Del: useless -- https://master.php.net/note/delete/124756/useless Del: bad code -- https://master.php.net/note/delete/124756/bad+code Del: spam -- https://master.php.net/note/delete/124756/spam Del: non-english -- https://master.php.net/note/delete/124756/non-english Del: in docs -- https://master.php.net/note/delete/124756/in+docs Del: other reasons-- https://master.php.net/note/delete/124756 Reject -- https://master.php.net/note/reject/124756 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214220) next »