Decimal() instead of float?
Michael B. Trausch
fd0man at gmail.com
Sat Nov 11 20:23:24 EST 2006
Is there a way to use Decimal() by default in Python instead of float?
I've no use for the float type, and I have some stuff that would require
Decimal(), but it is kind of a pain to try and cast things all over the
place all the time. Float is just way too inexact for me.
I am searching around, and I don't see anything helpful, but I could (as
always) be missing something... I tried (rather naïvely) to just do
something like:
>>> import decimal
>>> float=Decimal
>>> x=1.1
>>> x
1.1000000000000001
>>>
But, that didn't work (obviously). It was a shot, anyway. Are there
any ideas, or does anyone have a way around this? I would prefer to not
have to convert incoming floating point numbers to strings and then
convert them to Decimal() types every single time that I want to use
them (which would be in *every* case). For example, I have a ZIP code
database that can do some processing on its numbers, and the numbers are
stored as floating point values (exactly) but Python doesn't get them
right; so the Decimal() thing would be needed. *shrugs*
Thanks a bunch,
Mike
--
Michael B. Trausch
fd0man at gmail.com
Phone: (404) 592-5746
Jabber IM: fd0man at livejournal.com
Demand Freedom! Use open and free protocols, standards, and software!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061111/162e0bc4/attachment.html>
More information about the Python-list
mailing list