Doc #66866 [Opn->Nab]: Same output for float numbers when using variable handling functions
[email protected] Fri, 22 Apr 2022 13:13:40 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=66866&edit=1 ID: 66866 Updated by: [email protected] Reported by: jan dot kahoun at heureka dot cz Summary: Same output for float numbers when using variable handling functions -Status: Open +Status: Not a bug Type: Documentation Problem Package: Variables related Operating System: CentOS release 6.4 (Final) PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Since PHP 7.1 var_dump and the like also output the float in full precision. This ini option is documented here: https://www.php.net/manual/en/ini.core.php#ini.precision Previous Comments: ------------------------------------------------------------------------ [2018-08-23 18:57:37] php at sam002 dot net This is really misleading.The 'serialize_precision', the default value was recently made '-1'. Also need for 'precision'. ------------------------------------------------------------------------ [2014-03-09 18:26:54] jan dot kahoun at heureka dot cz Yes, that's true. So maybe it will be better to have same value for setting the "precision" and "serialize_precision" at default? I realy don't know why is better to have lower precision when displaying value? What are the usecases? I thought that for precision purpouses, there are relevant functions like round(), format_number(), ceil() and floor(). I'm not the only one who is facing with this strange behaviour. ;-) ------------------------------------------------------------------------ [2014-03-09 18:10:37] [email protected] echo/print() are used for debugging too all over the place. Having print_r() show a different value would lead to the exact same confusion. The best we can do is do a better job explaining the precision settings on the relevant doc pages. ------------------------------------------------------------------------ [2014-03-09 17:58:23] jan dot kahoun at heureka dot cz But functions var_dump() and print_r() are often used for debuging purpouses. So if you want to see what is actually in the variable you will not expect the rounded value. This is realy confusing. I think, that this should be at least mentioned on the all doc pages of the functions var_dump(), print_r() and var_export(). Thank you. ------------------------------------------------------------------------ [2014-03-09 17:31:44] [email protected] 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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=66866 -- Edit this bug report at https://bugs.php.net/bug.php?id=66866&edit=1