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 "decimal" module #32

Closed
Jellby opened this issue Oct 27, 2017 · 1 comment
Closed

Support "decimal" module #32

Jellby opened this issue Oct 27, 2017 · 1 comment

Comments

@Jellby
Copy link

Jellby commented Oct 27, 2017

Would be possible to support the decimal module, such that e.g. simple_eval('0.1+0.2') gives 0.3 instead of 0.30000000000000004?

@Jellby Jellby changed the title Support decimal Support "decimal" module Oct 27, 2017
@danthedeckie
Copy link
Owner

You can add this kind of thing yourself trivially:

import decimal
import simpleeval

class DecimalEval(simpleeval.SimpleEval):
    @staticmethod
    def _eval_num(node):
        return decimal.Decimal(node.n)

decimal.getcontext().prec = 1
DecimalEval().eval('0.1+0.2')

returns:

Decimal(0.3)

I'd rather keep simpleeval slim without adding this functionality to the base module. But it's a cool idea! Thanks for asking.

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

No branches or pull requests

2 participants