Giri Annamalai M
Giri Annamalai M

Reputation: 809

PHP dividing decimal/integer values gives round up output

When I'm dividing,

echo 50.3228679581385 / 100;
Output:0.50322867958139

It should be 0.503228679581385 . Is there any way to avoid default round up?

Upvotes: 0

Views: 31

Answers (2)

Narf
Narf

Reputation: 14752

Yes, there's an INI setting for that, where 14 is the default value:

; The number of significant digits displayed in floating point numbers.
; http://php.net/precision
precision = 14

Increase to 15 or more, as necessary. Also works at runtime like this:

ini_set('precision', 15);

Upvotes: 2

iamnoten
iamnoten

Reputation: 231

It's not default round up, it's because of the precision limit on double.

Upvotes: 1

Related Questions