[英]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
. 应该是
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: 是的,有一个INI设置,默认值为14:
;
; The number of significant digits displayed in floating point numbers.
浮点数中显示的有效位数。
;; http://php.net/precision
http://php.net/precision
precision = 14精度= 14
Increase to 15 or more, as necessary. 根据需要增加到15或更多。 Also works at runtime like this:
也可以在运行时像这样运行:
ini_set('precision', 15);
它不是默认的四舍五入,是因为对double的精度限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.