João Paulo
João Paulo

Reputation: 6710

PHP number more than 10 decimal places

I have this situation:

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

It's returning this:

{"value":8.8765434567877}

And not this, which is the desirable:

{"value":8.876543456787654}

Note that I can't have this:

{"value":"8.876543456787654"}

How can I change this precision and cancel the rounding?

Upvotes: 4

Views: 1089

Answers (1)

Matt The Ninja
Matt The Ninja

Reputation: 2731

Set precision higher at runtime

ini_set("precision", "16");

Also use (float) instead of (double)

Upvotes: 6

Related Questions