Doc #66866 [Opn->Nab]: Same output for float numbers when using variable handling functions

From: Date: Fri, 22 Apr 2022 13:13:40 +0000
Subject: Doc #66866 [Opn->Nab]: Same output for float numbers when using variable handling functions
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19420@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66866&edit=1

 ID:                 66866
 Updated by:         ilutov@php.net
 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] rasmus@php.net

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] rasmus@php.net

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


Thread (5 messages)

« previous php.doc.bugs (#19420) next »