Sorry... I'm ashamed to submit such awful code in my first post. Let me
try again...

from decimal import Decimal
def dec2long(number):
    """ Convert decimal.Decimal to long  """
    longstring = str(number)
    if "e" in longstring:
        radix, exponent = longstring.split("e")
    elif "E" in longstring:
        radix, exponent = longstring.split("E")
    else:
        radix, exponent = [longstring, "0"]
    floatexp = long(len(radix.split(".")[1]))
    floatish = Decimal(radix) * 10L**floatexp
    ftol = long(floatish)
    longexp = long(int(exponent) - floatexp)
    return ftol * 10L**longexp

This one should run by itself, is more readable and... still smells bad
:(
Sorry again.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to