PHP中的浮点运算不取整


Float not rounding in PHP

我有一个类似于4.0157725356416E+24的浮点数组,它们没有用round()取整。(看门狗是一个drupal日志记录工具)

$score = ($results['results'][0]['score']);
watchdog( 'multi', "float: $score");
$score = ($score * 100);
watchdog( 'multi', "percent (". gettype($score) . "): $score");
$score = round( $score );
watchdog( 'multi', "round: $score");

结果是:

> float: 1.9532660466727E+25
> percent (double): 1.9532660466727E+27
> round: 1.9532660466727E+27

我错过了什么。。。

您看到的是指数(即1.9532660466727*10^27)。它们仍然被四舍五入到最接近的整数,它们只是巨大的。

它与1953266046672700000000000 相同