note 81903 added to function.round
| From: | kjohnson at zootweb dot com | Date: | Tue, 18 Mar 2008 22:03:08 +0000 |
| Subject: | note 81903 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137185@lists.php.net to get a copy of this message | ||
Beware: round() has changed its behavior from PHP 4. For certain special numbers that seem to be
multiples of 100,000, the return value is in exponential format, rather than decimal. This is fine
as long as the number is only used internally to PHP. However, if you interpolate that value into
xml, as in this example, then you will likely end up with an xsd validation error and a failed
transaction:
'<AnnualIncome>' . round($income) . '</AnnualIncome>'
Some of these special values are 1200000, 1400000, 2300000, which are returned as 1.2E+6, etc. You
can generate your own list using this code:
<?php
for( $tmp = 0, $i = 0; $i < 100; $i++ ) {
$tmp += 100000;
echo round($tmp),"\n";
}
?>
I reported this as a bug, but it was rejected. Regardless of what it is, it will bite you if
you're not careful.
http://bugs.php.net/?id=44223&edit=2
----
Server IP: 64.71.164.2
Probable Submitter: 12.7.177.130
----
Manual Page -- http://www.php.net/manual/en/function.round.php
Edit -- https://master.php.net/note/edit/81903
Del: integrated -- https://master.php.net/note/delete/81903/integrated
Del: useless -- https://master.php.net/note/delete/81903/useless
Del: bad code -- https://master.php.net/note/delete/81903/bad+code
Del: spam -- https://master.php.net/note/delete/81903/spam
Del: non-english -- https://master.php.net/note/delete/81903/non-english
Del: in docs -- https://master.php.net/note/delete/81903/in+docs
Del: other reasons-- https://master.php.net/note/delete/81903
Reject -- https://master.php.net/note/reject/81903
Search -- https://master.php.net/manage/user-notes.php