$a]); He retu...">

PHP number more than 10 decimal places

I have this situation:

$a = (double)"8.876543456787654";
echo json_encode(["value" => $a]);

He returns this:

{"value":8.8765434567877}

And not this, which is desirable:

{"value":8.876543456787654}

Please note: I cannot do this:

{"value":"8.876543456787654"}

How can I change this precision and cancel rounding?

+4
source share
1 answer

Set accuracy higher at runtime

ini_set("precision", "16");

Also use (float)instead(double)

+5
source

Source: https://habr.com/ru/post/1650714/


All Articles