Tuesday, June 28, 2011

Re: Curious int/float/division/math 'gotcha' in py (discussion)

On Tue, Jun 28, 2011 at 2:41 PM, Cal Leeming [Simplicity Media Ltd]
<cal.leeming@simplicitymedialtd.co.uk> wrote:
> Yeah I have come up against horrible problems before when forcibly
> re-casting all int's to float's.. (especially when it's in the monetary
> sense). I had assumed that it would be a on a "per case" basis, but just
> wanted to make sure.

Eeek - having said hard and fast rules are bad, I'm going to give one
of my own - never ever ever use floating point calculations for
financial/monetary calculations. Use Decimal (which is in fact backed
by two integers), which avoids rounding issues.

When the auditors want to know what happened to the missing 4p* before
they sign off your books, you don't want to have to go through every
block of code retro-fitting Decimal :)



* This happened to me.

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment