Home >Backend Development >PHP Tutorial >高手开过来!PHP的bcmath问题你懂吗?

高手开过来!PHP的bcmath问题你懂吗?

WBOY
WBOYOriginal
2016-06-23 14:01:19828browse

$b=0.000000011;$post=100000000;$aa=strval($b);$pos=strval($post);echo bcmul($aa,$pos,10);echo '<br/>';$aa="0.000000011";$pos="100000000";echo bcmul($aa,$pos,10);

结果是:
0
1.100000000
为什么?强制转换跟直接赋值不一样?


回复讨论(解决方案)

$b=0.000000011;$aa=strval($b);var_dump($aa);

输出的结果是 string '1.1E-8' (length=6)
和 '0.000000011'是不一样的

科学计数法不是高精度计数法
所以 bcmath 不支持科学计数法
$b=0.000000011;
echo strval($b); //1.1E-8

那如何解决?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php图片上传问题Next article:这个json数据如何解析