decimal.Decimal as default type in stead of float

Viewed 29

Is it possible to change the "default" datatypes in python? Such that when I declare a variable with a value 0.2, it will be a decimal.Decimal in stead of a float? The only thing I could think of was this

>>> from decimal import Decimal
>>> float = Decimal
>>> float(".2")+float(".1")
Decimal('0.3')

Which is kinda the behaviour I wanted, but not quite:

>>> .2+.1
0.30000000000000004

I expected similar results as with float(".2")+float(".1"), but I guess x=.1 is handled differently than x=float(".1").

Is there any way to achieve the first behaviour without excplicitly calling float()?

0 Answers
Related