pdb.set_trace(), decimal, django, FloatField

!#%@#^@#$%@#% Decimal.

So the other evening was spent tracking down a damnable thing. in Python 2.4, the win32 implementation of Decimal (new in Python 2.4) doesn’t support multiplying a Decimal value by an integer. And that really bit hard.

Turns out, the whole reason I was dealing with Decimal was because of a terrible assumption I made. Somewhere in a recent version of the python MySQL drivers, they slipped in a return value type of Decimal for floats… damnit. Freakin’ bit me in the butt. Turns out that Django with MySQL on my MacOS X box was giving me back a Decimal python type when the python value was retrieved from a django FloatField. Win32, however, was returning a float.


In the end, I did a terrible thing – I put in an OS specific check in my code to convert the bloody thing to float so that it would at least be consistent. decimal.Decimal includes a handy .__float__() method.

Published by heckj

Joe has broad software engineering development and management experience, from startups to large companies. Joe works on projects ranging from mobile to multi-cloud distributed systems, has set up and led engineering teams and processes, as well as managing and running services. Joe also contributes and collaborates with a wide variety of open source projects, and writes online at https://rhonabwy.com/.

%d bloggers like this: