note 109731 added to function.round

From: Date: Wed, 15 Aug 2012 04:09:29 +0000
Subject: note 109731 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-190078@lists.php.net to get a copy of this message
I've got this strange precision problem: <?php $decimals = 1; $n=5.95; echo "<br>n=",$n," ==> ",round($n, $decimals); // 5.95 ==> 6 ! $n = ( 11.9 ) / 2; echo "<br>n=",$n," ==> ",round($n, $decimals); // 5.95 ==> 6 ! $n = ( 2.7 + 9.2 ) / 2; echo "<br>n=",$n," ==> ",round($n, $decimals); // 5.95 ==> 5.9 ?? ?> To adjust it, i've done: <?php $n = ( 2.7 + 9.2 ) / 2; $n += pow (10, -( $decimals + 2)) * 1; echo "<br>n=",$n," ==> ",round($n, $decimals); // 5.951 ==> 6 ! ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.19.122.174 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/109731 Del: integrated -- https://master.php.net/note/delete/109731/integrated Del: useless -- https://master.php.net/note/delete/109731/useless Del: bad code -- https://master.php.net/note/delete/109731/bad+code Del: spam -- https://master.php.net/note/delete/109731/spam Del: non-english -- https://master.php.net/note/delete/109731/non-english Del: in docs -- https://master.php.net/note/delete/109731/in+docs Del: other reasons-- https://master.php.net/note/delete/109731 Reject -- https://master.php.net/note/reject/109731 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190078) next »