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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:01:19
Original
858 people have browsed it

$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);
Copy after login

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


回复讨论(解决方案)

$b=0.000000011;$aa=strval($b);var_dump($aa);
Copy after login

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

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

那如何解决?

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template