N
N
Nubbin2018-02-15 20:59:41
PHP
Nubbin, 2018-02-15 20:59:41

Why are there large values ​​in JSON?

Good night.
Guys why when you open JSON there are big values.
How to
trim
them?
number_format() I use before generating json document

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shamsudin Serderov, 2018-02-15
@Nubbin

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}

A
Artem Volkov, 2018-02-15
@AronTito

<?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 question

Ask a Question

731 491 924 answers to any question