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

"E" gets converted to 2.718281828459045 #178

Closed
dupski opened this issue Oct 18, 2018 · 3 comments
Closed

"E" gets converted to 2.718281828459045 #178

dupski opened this issue Oct 18, 2018 · 3 comments

Comments

@dupski
Copy link
Contributor

dupski commented Oct 18, 2018

Hey guys. Sorry for raising a new issue for this but just searching for "E" is not very helpful :)

We have a formula: C+D+E+F+G/H

Unfortunately expr-eval converts it to ((((C + D) + 2.718281828459045) + F) + G) / H

I'm guessing because https://en.wikipedia.org/wiki/E_(mathematical_constant) ?

How do I stop expr-eval from changing E to 2.7182.... ?

Thanks!

@dupski
Copy link
Contributor Author

dupski commented Oct 18, 2018

Looks like a workaround is to convert the variable names to Lowercase, so I'll go with that for now, but I'll leave this issue open as it would be good to know / document :)

Thanks for the awesome library :)

@silentmatt
Copy link
Owner

You are correct that it's replacing it because of Euler's constant, and lowercasing does work around it, because the constant name is E and is case-sensitive.

If you're not going to need it, you can remove it by either deleting E from parser.consts, or replacing the consts field altogether to remove all the built-in constants (E, PI, true, and false).

Here's an example:

var parser = new Parser();
console.log(parser.parse('C+D+E+F+G/H').toString()); // ((((C + D) + 2.718281828459045) + F) + (G / H))

delete parser.consts.E; // or use "parser.consts = {};" to remove everything

console.log(parser.parse('C+D+E+F+G/H').toString()); // ((((C + D) + E) + F) + (G / H))

You're also right that this should definitely be documented :)

@dupski
Copy link
Contributor Author

dupski commented Oct 21, 2018

#179 :)

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