note 83577 added to language.types.float
| From: | kjohnson at zootweb dot com | Date: | Mon, 02 Jun 2008 19:23:59 +0000 |
| Subject: | note 83577 added to language.types.float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140071@lists.php.net to get a copy of this message | ||
PHP switches from the standard decimal notation to exponential notation for certain
"special" floats. You can see a partial list of such "special" values with this:
<?php
for( $tmp = 0, $i = 0; $i < 100; $i++ ) {
$tmp += 100000;
echo round($tmp),"\n";
}
?>
So, if you add two floats, end up with a "special" value, e.g. 1.2E+6, then put that value
unmodified into an update query to store the value in a decimal column, say, you will likely get a
failed transaction, since the database will see "1.2E+6" as varchar data, not decimal.
Likewise, you will likely get an XSD validation error if you put the value into xml.
I have to be honest: this is one of the strangest things I have seen in any language in over 20
years of coding, and it is a colossal pain to work around.
----
Server IP: 69.147.83.197
Probable Submitter: 12.7.177.130
----
Manual Page -- http://www.php.net/manual/en/language.types.float.php
Edit -- https://master.php.net/note/edit/83577
Del: integrated -- https://master.php.net/note/delete/83577/integrated
Del: useless -- https://master.php.net/note/delete/83577/useless
Del: bad code -- https://master.php.net/note/delete/83577/bad+code
Del: spam -- https://master.php.net/note/delete/83577/spam
Del: non-english -- https://master.php.net/note/delete/83577/non-english
Del: in docs -- https://master.php.net/note/delete/83577/in+docs
Del: other reasons-- https://master.php.net/note/delete/83577
Reject -- https://master.php.net/note/reject/83577
Search -- https://master.php.net/manage/user-notes.php