简体   繁体   中英

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?

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);

它不是默认的四舍五入,是因为对double的精度限制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM