The v20.Context class accepts a constructor parameter decimal_number_as_float=True
This flag is used in the Context.convert_decimal_number method, used by everything else to parse rational numbers returned in the API responses. By default it converts these all from strings to the native float type allowing arithmetic etc..
However, I would like the Python Decimal class to be used as it can guarantee exact precision when performing arithmetic.
One way to get around this is to sub-class the Context, e.g.
import v20
from decimal import Decimal
class DecimalContext(v20.Context):
def convert_decimal_number(self, value):
return Decimal(value)
The
v20.Context
class accepts a constructor parameterdecimal_number_as_float=True
This flag is used in the
Context.convert_decimal_number
method, used by everything else to parse rational numbers returned in the API responses. By default it converts these all from strings to the nativefloat
type allowing arithmetic etc..However, I would like the Python
Decimal
class to be used as it can guarantee exact precision when performing arithmetic.One way to get around this is to sub-class the Context, e.g.
References: