doub1ejack
doub1ejack

Reputation: 11171

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...

Upvotes: 0

Views: 188

Answers (1)

Matt
Matt

Reputation: 7040

You're looking at exponential numbers (i.e. 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

Upvotes: 3

Related Questions