PHP 7.1 added support for more precise float encoding in json_encode
cjhaas opened this issue · 1 comments
cjhaas commented
Not sure the best way to add this while supporting backwards compatibility.
https://wiki.php.net/rfc/precise_float_value
This test fails in PHP7.1+:
$data = [1.0, 1.1, 0.00000000001, 1.999999999999, 223423.123456789, 1e5, 1e11];
$expected = '[1.0,1.1,1.0e-11,1.999999999999,223423.12345679,100000.0,100000000000.0]';
$this->assertSame($expected, $this->serializer->serialize($data));
1) Zumba\JsonSerializer\Test\JsonSerializerTest::testSerializeFloatLocalized
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-[1.0,1.1,1.0e-11,1.999999999999,223423.12345679,100000.0,100000000000.0]
+[1.0,1.1,1.0e-11,1.999999999999,223423.123456789,100000.0,100000000000.0]
jrbasso commented
The solution wasn't pretty, but I guess it's reasonable. The output of both cases are valid, and the decoding is going to work in both cases. So I don't think it needs to give the same output when it's an enhancement from the language itself.