|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-09-12 03:31 UTC] daniel dot oconnor at gmail dot com
Description:
------------
var_dump() does not show the actual value of floats; but rather performs rounding before rendering.
This can lead to hard to decipher loss of precision bugs. If you then use var_dump() to try to compare output, you aren't going to find the *actual* values of the numbers you are comparing.
For this reason, I'd like to ask var_dump() renders the complete representation of the number; where needed in scientific notation.
Reproduce code:
---------------
<?php
function variance($a, $b) {
return (double)100.00 - (double)(($a/$b) * 100.00);
}
var_dump(12.99); //12.99
var_dump(variance(87.01, 100.00)); //12.99
var_dump(variance(87.01, 100.00) - 12.99); //difference <-5.3290705182008E-15>
Expected result:
----------------
---------- php ----------
float(12.99)
float(12.99) // should be 12.99 + -5.3290705182008E-15
float(-5.3290705182008E-15)
Output completed (0 sec consumed) - Normal Termination
Actual result:
--------------
---------- php ----------
float(12.99)
float(12.99)
float(-5.3290705182008E-15)
Output completed (0 sec consumed) - Normal Termination
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 23 10:00:01 2025 UTC |
This is not a bug. Do a ini_set('precision',32) at the top of your script, for example, if you want a higher precision estimation of the float.