The answer to your first question: yes, round been fixed in Python 2.7.
The answer to your second question is: I'm not sure if not using earlier Python (2.6 should still demonstrate 2.4 behavior). In this particular case, your value is indistinguishable from 1480.395 and 1480.395 (for us, based on 10 people) rounds to 1480.40. Therefore, I assume that you can try to round to one place first, except that you really actually turn it into a string, and then get the decimal number from this ... but, unfortunately, I can't think of anything, which does not include Decimal. If I come up with something (before someone else writes something better), I will go back and edit.
(But really, is Decimal all that hard to use?)
Edit: Here is an example using a decimal number:
>>> from decimal import Decimal >>> f = Decimal('1480.395') >>> f.quantize(Decimal('0.00')) Decimal('1480.40') >>> float(Decimal('1480.40')) 1480.4
Some notes:
Python 2.7 allows you to use float as input for Decimal. Do not do this , as you will return to where you started. Also, do not use the built-in round function in the decimal system, because this function converts your decimal right back to a float, and thus, you return to where you started. In its simplest form, Decimal quantize takes another decimal number, which has the number of decimal places you really want (think of it as a rounding pattern). If your data absolutely must be float, then only convert back to float after all your Decimal calculations are complete.
Finally: I'm not sure if this covers all of the possible weird corner cases in Python 2.4 floating point behavior. If you rely on the exact behavior of Python 2.4, there can be no replacement for Python 2.4. What I described above is just one step closer to rounding a person.
source share