简体   繁体   中英

Float not rounding in PHP

I have an array of floats similar to 4.0157725356416E+24 that are not being rounded with round() . (watchdog is a drupal logging tool)

$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");

and the out put of this is:

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

I'm missing something here...

You're looking at exponential numbers (ie 1.9532660466727 * 10 ^ 27). They are still being rounded to the nearest integer, they're just HUGE.

It's the same as 1,953,266,046,672,700,000,000,000,000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM