Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The currently json_encode()
used value is EG (precision), which is set to 14. This means that a maximum of 14 digits are used to display (print) the number. IEEE 754 double supports higher precision and serialize()/ or var_export() uses PG (serialize_precision) which should be more precise by default. Since json_encode() uses EG (precision), json_encode() removes the bottom digits of the fraction parts and destroys the original value, even though PHP's float may contain a more precise float value.
And (my attention)
In short, there is a new way to force PHP 7.1 json_encode to use the new and improved precision mechanism. In php.ini you need to change serialize_precision to
.
You can check if it works with this command line
You must receive{"price":45.99}
<?php
echo ceil(4.3); // 5
echo ceil(9.999); // 10
echo ceil(-3.14); // -3
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question