note 95627 deleted from function.round by danbrown
| From: | danbrown@php.net | Date: | Wed, 13 Jan 2010 15:50:52 +0000 |
| Subject: | note 95627 deleted from function.round by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164921@lists.php.net to get a copy of this message | ||
Note Submitter: cpopa at nu-dawn dot ca
----
//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!