[issue2140] calculation bug in long() function
Changes by Markus Stoll: -- components: None nosy: must21 severity: normal status: open title: calculation bug in long() function type: behavior versions: Python 2.1.1, Python 2.1.2, Python 2.2, Python 2.2.1, Python 2.2.2, Python 2.2.3, Python 2.3, Python 2.4, Python 2.5 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2140> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2140] calculation bug in long() function
New submission from Markus Stoll: betrag = 146.95 betrag = float(betrag) betrag = betrag * 100.0 betrag = long(betrag) print betrag gives 14694 as result rather than 14695 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2140> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2140] calculation bug in long() function
Markus Stoll added the comment: 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.94 > > In binary you can not express this number exactly. > >>>> 146.95 * 100 > 14694.9998 > > 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 <[EMAIL PROTECTED]> > <http://bugs.python.org/issue2140> > __ __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2140> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com