Bug #79355 [Com]: number round + jscon_decode generate mistery numbers
| From: | php at cylancer dot net | Date: | Mon, 09 Mar 2020 08:32:35 +0000 |
| Subject: | Bug #79355 [Com]: number round + jscon_decode generate mistery numbers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225963@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79355&edit=1
ID: 79355
Comment by: php at cylancer dot net
Reported by: php at cylancer dot net
Summary: number round + jscon_decode generate mistery numbers
Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: Debian Buster 64Bit
PHP Version: 7.3.15
Block user comment: N
Private report: N
New Comment:
Thank you very much. The "serialize_precision" was really set to an absurdly high value.
Unfortunately I did not recognize the connection.
If possible, I withdraw my bug report.
Thanks again for the quick clarification and help.
Best regards
Clemens
Previous Comments:
------------------------------------------------------------------------
[2020-03-09 08:16:25] nikic@php.net
You likely have serialize_precision set to some unnecessarily high value. Please leave
serialize_precision at the default of -1, unless you really know what you're doing.
------------------------------------------------------------------------
[2020-03-08 23:26:00] requinix@php.net
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2020-03-08 23:21:06] php at cylancer dot net
Description:
------------
I use the PHP Version 7.3.14-1~deb10u1
After Json decoding, rounded numbers have many unexpected decimal places.
Test script:
---------------
$a = 4;
$b = 6;
$c = $a * 100 / $b;
echo '$c = '. $c." \n\n";
$d = round($c, 1); // the second parameter is important
echo '$d = round($c, 1);'."\n\n";
echo '$d = '.$d. ' <--- is rounded $c'."\n\n";
echo 'if i decode my result to json... '."\n\n";
echo json_encode($d)."\n\n";
echo 'then my number is not rounded.'."\n\n";
The output is:
$c = 66.6666666667
$d = round($c, 1);
$d = 66.7 <--- is rounded $c
if i decode my result to json...
66.7000000000000028421709430404007434844970703125
then my number is not rounded.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79355&edit=1