Issue2140
Created on 2008-02-18 12:18 by must21, last changed 2008-02-18 12:55 by must21.
| msg62523 (view) |
Author: Markus Stoll (must21) |
Date: 2008-02-18 12:18 |
|
betrag = 146.95
betrag = float(betrag)
betrag = betrag * 100.0
betrag = long(betrag)
print betrag
gives 14694 as result rather than 14695
|
| msg62524 (view) |
Author: Facundo Batista (facundobatista) |
Date: 2008-02-18 12:25 |
|
In short:
>>> long(100 * 146.95)
14694L
This is NOT a bug, but a behaviour of binary floating point:
>>> 146.95
146.94999999999999
In binary you can not express this number exactly.
>>> 146.95 * 100
14694.999999999998
When you long() that, you truncate the number, so it goes to 14694.
Please address further discussion through python-list.
Thanks!
|
| msg62526 (view) |
Author: Markus Stoll (must21) |
Date: 2008-02-18 12:55 |
|
thank you for fast reply
I see the point and do not want to argue about that (rounding is fine
for me). I just think this behaviour makes the long() function pretty
much useless.
Regards, Markus
Am 18.02.2008 um 13:25 schrieb Facundo Batista:
>
> Facundo Batista added the comment:
>
> In short:
>
>>>> long(100 * 146.95)
> 14694L
>
> This is NOT a bug, but a behaviour of binary floating point:
>
>>>> 146.95
> 146.94999999999999
>
> In binary you can not express this number exactly.
>
>>>> 146.95 * 100
> 14694.999999999998
>
> When you long() that, you truncate the number, so it goes to 14694.
>
> Please address further discussion through python-list.
>
> Thanks!
>
> ----------
> nosy: +facundobatista
> resolution: -> invalid
> status: open -> closed
>
> __________________________________
> Tracker <report@bugs.python.org>
> <http://bugs.python.org/issue2140>
> __________________________________
|
|
| Date |
User |
Action |
Args |
| 2008-02-18 12:55:36 | must21 | set | messages:
+ msg62526 |
| 2008-02-18 12:25:04 | facundobatista | set | status: open -> closed resolution: invalid messages:
+ msg62524 nosy:
+ facundobatista |
| 2008-02-18 12:18:18 | must21 | set | messages:
+ msg62523 |
| 2008-02-18 12:18:06 | must21 | create | |
|