note 95627 added to function.round
| From: | cpopa at nu-dawn dot ca | Date: | Wed, 13 Jan 2010 06:14:50 +0000 |
| Subject: | note 95627 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164903@lists.php.net to get a copy of this message | ||
//choose 2 variables:
$a=20.5;
$b=74.49;
$c=$a*$b; //(would be 1527.045)
//if we round() $c to 2 decimals we get:
round($c,2)=1527.04 // WRONG!!!
//but if we add in before rounding this:
settype($c,"string");// only string works!!!
//boolean,integer,float,double all would trigger wrong results
//and than
round($c,2)=1527.05; // we get RIGHT!
//if we say:
$D=1527.045;
round($D)=1527.05; // we get RIGHT!
----
Server IP: 66.207.199.35
Probable Submitter: 174.3.81.225
----
Manual Page -- http://www.php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/95627
Del: integrated -- https://master.php.net/note/delete/95627/integrated
Del: useless -- https://master.php.net/note/delete/95627/useless
Del: bad code -- https://master.php.net/note/delete/95627/bad+code
Del: spam -- https://master.php.net/note/delete/95627/spam
Del: non-english -- https://master.php.net/note/delete/95627/non-english
Del: in docs -- https://master.php.net/note/delete/95627/in+docs
Del: other reasons-- https://master.php.net/note/delete/95627
Reject -- https://master.php.net/note/reject/95627
Search -- https://master.php.net/manage/user-notes.php