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

Allow treating all number literals as BigDecimals to avoid NumberFormatExceptions #503

Merged
merged 3 commits into from
May 1, 2020

Conversation

eXsio
Copy link
Contributor

@eXsio eXsio commented Apr 22, 2020

If a literal is big enough, with current implementation there will be a NumberFormatException thrown during the processing of the Template. There should be an option to treat all number literals as BigDecimals. It will help avoiding this exception and also enforce precise arithmetics when performing calculations.

@ebussieres
Copy link
Member

ebussieres commented Apr 30, 2020

I'll need to run some benchmark with these changes. But it sounds good to me.

Can you adjust the documentation too with the new option in this PR ?

@ebussieres ebussieres added this to the 3.1.3 milestone Apr 30, 2020
@eXsio
Copy link
Contributor Author

eXsio commented Apr 30, 2020

Sure, docs updated. Setting this option to true may indeed cause some small performance degradation (BigDecimals are slower than Longs/Doubles by nature). I'd still keep it for folks that would rather sacrifice a bit of performance but gain 100% precision when doing math.

In my use case I'm using Pebble as an expression evaluation engine (to calculate Excel-like formulas using my own set of Functions and Operators) and this option is vital to me - without it I have to make workarounds by creating custom Functions to explicitly convert String-based args to BigDecimals.

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

Successfully merging this pull request may close these issues.

2 participants