ffrey schrieb:
> Total madness !
> $v = (float) ((0.7 + 0.1) * 10);echo $v; => 8, as expected
> 
> $v = (int) ((0.7 + 0.1) * 10);echo $v; => 7, as totally unexpected !!!
> 
> Can you explain why ? A php bug ?
> Thanks for that thought-provoking post ;-)

Just never cast floats to integers directly, use round() instead, this 
will clear the float-specific inaccuracy:

$v = (int) round((0.7 + 0.1) * 10);

Your code is in fact the same as this:

$v = (int) floor((0.7 + 0.1) * 10);

and floor(7.99999999999999) is still 7.

And to follow Thomas' reply: yes, this is a PHP thing, not a symfony thing.

David

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to