Closed thiemowmde closed 6 years ago
Looking at the PHP sources (https://github.com/php/php-src/blob/414aaa207cc59c279d3fd5ed83f6b92890e57023/Zend/zend_operators.c#L560), I think you could also use sprintf("%.17G", $number);
here (although it is to note that this is probably not using the same code path as serialize does, which uses gcvt
internally).
Although sprintf
can use a localized decimal point, which serialize can't (hard coded to .
).
I heavily updated the patch to use sprintf with %e now. That was new to me (and is not well documented, unfortunately). It indeed allows to format floats with a fixed number of significant digits, which is what we need here.
I played around with the float-to-string conversion, tried a lot of different approaches I already tried before, and found a new one:
This patch fixes two of the listed issues, and (I believe) avoids all others:
serialize()
, the locale does not matter any more.Bug: T155910