为什么PHP会在输出上转换15位以上的数字长整数 [英] Why does PHP transform 15+ digit long integer on output
本文介绍了为什么PHP会在输出上转换15位以上的数字长整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么echo 100000000000000;
输出1.0E+14
而不输出100000000000000
?
这种整数的变换输出仅在15位或更长的整数上发生.
This kind of transformation of integers on output happens only for integers that are 15 digits long and longer.
推荐答案
如果大于PHP_INT_MAX,PHP会将整数转换为float.对于32位系统,该值为2147483647.
PHP will convert an integer to float if it is bigger than PHP_INT_MAX. For 32-bit systems this is 2147483647.
问题的答案与PHP中float的字符串表示形式有关.
The answer to the questions is related to the string representation of floats in PHP.
如果科学计数法中的指数大于13
或小于-4
,PHP将在打印浮点数时使用科学的表示形式.
If the exponent in the scientific notation is bigger than 13
or smaller than -4
, PHP will use scientific representation when printing floats.
示例:
echo 0.0001; // 0.0001;
echo 0.00001; // 1.0E-5
// 14 digits
echo 10000000000000; // 10000000000000
// 15 digits
echo 100000000000000; // 1.0E+14
请参见浮动vs.双精度
这篇关于为什么PHP会在输出上转换15位以上的数字长整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文