Recently, my local environment has started echoing/saving floats with two decimal points with an additional string of numbers at the end, resulting in inaccurate numbers. This behaviour is recent; it used to behave correctly. I can't think of anything that has particularly changed.
For a truly simple, example:
echo 18.99;
This outputs:
18.989999999999998
When I json_encode
an array with the value, the problem is exacerbated:
[18.989999999999998436805981327779591083526611328125]
Any idea what could be causing this issue, and how I might fix it? PHP 7.1, MacOS High Sierra 10.13.2, if it helps. Additionally, I'm using Laravel 5.5 as my framework.
Per some research I've already done, I tried changing the php_ini setting for precision
to 12
, 14
, and 17
, respectively. No change.
EDIT: I have seen other questions relating to the accuracy of floating point numbers in PHP and other languages, but as I've said, this behaviour is recent, so I don't believe this is simply an inherent flaw in the language.