note 81903 deleted from function.round by jani
| From: | jani@php.net | Date: | Thu, 10 Apr 2008 08:47:03 +0000 |
| Subject: | note 81903 deleted from function.round by jani | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138096@lists.php.net to get a copy of this message | ||
Note Submitter: kjohnson at zootweb dot com
----
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