How to handle data in the form of 3.5527136788005e-15 in PHP gracefully
PHP中文网
PHP中文网 2017-05-24 11:33:46
0
2
1338
-3.5527136788005e-15
3.5527136788005e-15

php Under what circumstances will such scientific notation appear?
Is there a function that can directly approximate 0?
Have you ever encountered this?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
仅有的幸福
$num = 3.5527136788005e-15;

var_dump(number_format($num));

One step to get it right:

$num = $num < 1 ? 0 : number_format($num, 2);
var_dump($num);

Reference: number_format

世界只因有你

If the decimal point exceeds a few decimal points, it will appear and can be set. If the data is not required to be accurate, rounding can be done

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template