I'm aware of the new serialize_precision
setting in php.ini, It is set to -1
and precision
is 14
by default.
The result of the php -r 'echo json_encode(2.49);'
command is 2.49
, as expected. But result of php -r 'echo json_encode(2.09 + 0.4);'
is 2.4899999999999998
.
Why and how to fix it without changing php.ini configuration?
EDIT:
To explain more - this is not the issue with float math, this is about json_encode() issue, because plain addition php -r 'echo 2.09 + 0.4;'
produces correct result of 2.49
.
My PHP version:
PHP 7.2.0-2+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Dec 7 2017 20:14:31) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.0-2+ubuntu16.04.1+deb.sury.org+2, Copyright (c) 1999-2017, by Zend Technologies
Thanks!