Closed remcotolsma closed 2 years ago
Added a test to reproduce this issue: https://github.com/pronamic/wp-number/commit/13e49a5da0f0ba621206a0a57d8dca8bdcf4ff32
Should we always set serialize_precision
to -1
or should we simplify this by using (string) $float
?
I think we should go for the serialize_precision
to -1
approach. The (string) $float
behaviour can also be influenced via the precision
option.
<?php
ini_set( 'serialize_precision', 17 );
ini_set( 'precision', 17 );
$value = 29.95;
var_dump( json_encode( $value ) );
var_dump( (string) $value );
https://wiki.php.net/rfc/precise_float_value
Since we use json_encode
we only have to temporary set serialize_precision
to -1
.
https://secure.helpscout.net/conversation/1696891636/23013?folderId=1425713
I can reproduce this issue on a Local WordPress installation.
After some debugging i think this has something to do with
serialize_precision
configuration option.I couldn't reproduce this setting via PHPUnit or via https://3v4l.org/, it seems that
serialize_precision
is set to-1
in these environments:If we set
serialize_precision
to17
it's behaviour changes: