Mr. Felix Mr. Felix - 1 year ago 134
PHP Question

PHP number more than 10 decimal places

I have this situation:

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

It's returning this:


And not this, which is the desirable:


Note that I can't have this:


How can I change this precision and cancel the rounding?

Answer Source

Set precision higher at runtime

ini_set("precision", "16");

Also use (float) instead of (double)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download