Re: [PHP] Loss of precision in intval()

2007-08-07 Thread Richard Lynch
On Wed, August 1, 2007 11:52 am, Mark Summers wrote: This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? What did you get? What did you expect? Do you have ANY idea how floats are actually represented internally in every computer language? [*] If you

Re: [PHP] Loss of precision in intval()

2007-08-07 Thread Bruce Cowin
Richard's right. You get the same result if you do the equivalent in ASP. Regards, Bruce Richard Lynch [EMAIL PROTECTED] 8/08/2007 3:29:16 p.m. On Wed, August 1, 2007 11:52 am, Mark Summers wrote: This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ?

Re: [PHP] Loss of precision in intval()

2007-08-02 Thread Roberto Mansfield
Those numbers must fall on the other side of the number. E.g., 75.81 == 75.8100011 (etc) so you get the expected results. Mark Summers wrote: I like to think that I'm reasonably aware of the limitations of floating point (famous last words). To my mind, the ridiculousness (probably

[PHP] Loss of precision in intval()

2007-08-01 Thread Mark Summers
This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Eric Butera
On 8/1/07, Mark Summers [EMAIL PROTECTED] wrote: This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What exactly were you expecting it to do? :)

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread tg-php
Very weird and counter intuitive. Looking at the php manual, I see this: Converting to integer from floating point: When converting from float to integer, the number will be rounded towards zero. But you'd think the multiplication would happen before the rounding. if you do: $a = ceil(75.82

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread tg-php
Probably return 7582 instead of 7581. = = = Original message = = = On 8/1/07, Mark Summers [EMAIL PROTECTED] wrote: This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Satyam
It is most definitely not if what you want is the square root, or the hyperbolic cosine or any other of a zillion things. - Original Message - From: Mark Summers [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, August 01, 2007 6:52 PM Subject: [PHP] Loss of precision

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Roberto Mansfield
Internally, 75.82 can't be stored exactly, so 75.82 * 100 is probably 7581.92 rather than the expected integer value of 7582. So intval is behaving properly. Sounds like you want intval(round($a)); [EMAIL PROTECTED] wrote: Very weird and counter intuitive. Looking at the php manual, I see

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Eric Butera
On 8/1/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Probably return 7582 instead of 7581. = = = Original message = = = On 8/1/07, Mark Summers [EMAIL PROTECTED] wrote: This sort of thing really isn't helpful... ?php $a = 75.82 * 100; echo intval($a); ? -- PHP General

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread David Duong
Roberto Mansfield wrote: Internally, 75.82 can't be stored exactly, so 75.82 * 100 is probably 7581.92 rather than the expected integer value of 7582. So intval is behaving properly. Sounds like you want intval(round($a)); [EMAIL PROTECTED] wrote: Very weird and counter intuitive.

Re: [PHP] Loss of precision in intval()

2007-08-01 Thread Mark Summers
I like to think that I'm reasonably aware of the limitations of floating point (famous last words). To my mind, the ridiculousness (probably not a word) of the example is highlighted by the fact that 75.81 and 75.83 work perfectly. Roberto Mansfield wrote: Internally, 75.82 can't be stored