|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-03-09 17:21 UTC] jan dot kahoun at heureka dot cz
Description: ------------ I know that the floating point values have a limited precision and hence a value might not have the same string representation after any processing. But it is possible to make var_dump(), print_r() and var_export() functions to output same result for float numbers? Some times the different output results leads to hard debuging ;-) If this is not possible, please mention this "feature" in the documentation of the functions. Thank you. Test script: --------------- $x = 0.399999999999999855671006798729649744927883148193359375; print_r($x); var_export($x); var_dump($x); Expected result: ---------------- Same result for all functions: print_r() = 0.399999999999999855671006798729649744927883148193359375 var_export() = 0.399999999999999855671006798729649744927883148193359375 var_dump() = float(0.399999999999999855671006798729649744927883148193359375) Actual result: -------------- print_r() = 0.4 var_export() = 0.399999999999999855671006798729649744927883148193359375 var_dump() = float(0.4) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 09:00:01 2025 UTC |
var_export() is fundamentally different from print_r() and var_dump() in that it is often used to read data back in. As such it is closer to serialize() than the others which are display-only functions. For display purposes PHP has the 'precision' ini setting and for serialize-purposes we have serialize_precision. In you script, if you do: echo ini_set('precision',ini_get('serialize_precision')); At the top you should get the same value for all three. But yes, this probably should be mentioned on the var_export doc page.