Re: [PHP] sprintf() oddness

2007-12-03 Thread Andrew Ballard
On Dec 3, 2007 3:29 PM, tedd <[EMAIL PROTECTED]> wrote: > At 2:04 PM -0500 12/3/07, Andrew Ballard wrote: > > > >Oh, man I'm having flashbacks to a flame war that broke out on a > >SQL Server board I read related to "bankers rounding" versus > >"traditional rounding" and which was more "correct

Re: [PHP] sprintf() oddness

2007-12-03 Thread tedd
At 2:04 PM -0500 12/3/07, Andrew Ballard wrote: Oh, man I'm having flashbacks to a flame war that broke out on a SQL Server board I read related to "bankers rounding" versus "traditional rounding" and which was more "correct" or "accurate". :-) Andrew There really shouldn't be a debate on

Re: [PHP] sprintf() oddness

2007-12-03 Thread Andrew Ballard
On Dec 1, 2007 11:30 AM, tedd <[EMAIL PROTECTED]> wrote: > At 7:10 AM -0500 12/1/07, Christoph Boget wrote: > >Why does > > > >sprintf( '%.03f', 0.1525 ) > > > >return 0.152 while > > > >sprintf( '%.03f', 0.1575 ) > > > >return 0.158? > > > >The 4th significant digit in both cases is '5' bu

Re: [PHP] sprintf() oddness

2007-12-02 Thread Martin Alterisio
2007/12/1, Christoph Boget <[EMAIL PROTECTED]>: > > Why does > > sprintf( '%.03f', 0.1525 ) > > return 0.152 while > > sprintf( '%.03f', 0.1575 ) > > return 0.158? > Welcome to the world of f floating point numbers. Discrete mathematics, leave all hope, ye that enter. It's the way fl

Re: [PHP] sprintf() oddness

2007-12-02 Thread tedd
At 6:08 AM -0500 12/2/07, Christoph wrote: If the general rule is to round up for 5s when preceeding is odd and round down when even, that's not occuring here when using round(). No, you're not reading what I wrote. I said MY general rule is to round up when the preceding digit is even, wher

Re: [PHP] sprintf() oddness

2007-12-02 Thread Christoph
The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprintf() basing it's decision on the value of the 3rd significant digit? If so, why? Shouldn't rounding decisions be based on subsequent digits and not preceding

Re: [PHP] sprintf() oddness

2007-12-01 Thread tedd
At 7:10 AM -0500 12/1/07, Christoph Boget wrote: Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprint

Re: [PHP] sprintf() oddness

2007-12-01 Thread Per Jessen
Jochem Maas wrote: > Per Jessen wrote: >> Christoph Boget wrote: >> >>> Why does >>> >>> sprintf( '%.03f', 0.1525 ) >>> return 0.152 while >>> sprintf( '%.03f', 0.1575 ) >>> return 0.158? > > most likely it's an artifact of the fact that > the binary representations of those floating poi

Re: [PHP] sprintf() oddness

2007-12-01 Thread Jochem Maas
Per Jessen wrote: > Christoph Boget wrote: > >> Why does >> >> sprintf( '%.03f', 0.1525 ) >> return 0.152 while >> sprintf( '%.03f', 0.1575 ) >> return 0.158? most likely it's an artifact of the fact that the binary representations of those floating point values are not exact e.g. 0.1575

Re: [PHP] sprintf() oddness

2007-12-01 Thread Per Jessen
Christoph Boget wrote: > Why does > > sprintf( '%.03f', 0.1525 ) > return 0.152 while > sprintf( '%.03f', 0.1575 ) > return 0.158? > > I am using PHP 4.3.11 I see the same behaviour in 5.2.4 /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

[PHP] sprintf() oddness

2007-12-01 Thread Christoph Boget
Why does sprintf( '%.03f', 0.1525 ) return 0.152 while sprintf( '%.03f', 0.1575 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprintf() basing it's decision on the value of the 3rd si