|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-02-24 14:35 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2020-02-24 14:35 UTC] nikic@php.net
[2020-02-24 14:39 UTC] dirk dot gerigk at atraveo dot com
[2020-02-24 14:43 UTC] bugreports at gmail dot com
[2020-02-24 14:45 UTC] nikic@php.net
[2020-02-24 14:49 UTC] dirk dot gerigk at atraveo dot com
[2020-02-24 14:53 UTC] nikic@php.net
[2020-02-24 15:01 UTC] dirk dot gerigk at atraveo dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
Description: ------------ Please have short look at the test code. If you do an float number calculation sometimes it results invalid result, when you bind the result directly into a class variable. An var_export() shows the wrong calculation, but if you cast the class property to string the value is right again (last line in the foreach). The wired part is that it not is always the case (see "11.8", "2.5"). What is wrong here? Test script: --------------- class X { public $v = null; } $x = new X(); foreach(["32.3","11.8","2.5"] as $float){ print ((float)(string)$float * 1000).PHP_EOL; $x->v = (float)(string)$float * 1000; print var_export($x->v,true).PHP_EOL; print "{$x->v}\n"; } Expected result: ---------------- 32300 32300.0 32300 11800 11800.0 11800 2500 2500.0 2500 Actual result: -------------- 32300 32299.999999999996 32300 11800 11800.0 11800 2500 2500.0 2500