Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python Decimal #38

Open
HarryR opened this issue Jun 25, 2020 · 0 comments
Open

Support Python Decimal #38

HarryR opened this issue Jun 25, 2020 · 0 comments

Comments

@HarryR
Copy link

HarryR commented Jun 25, 2020

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)

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant