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

how to set the scale like BigDecimal #283

Closed
Rocky-Hu opened this issue Dec 21, 2021 · 3 comments
Closed

how to set the scale like BigDecimal #283

Rocky-Hu opened this issue Dec 21, 2021 · 3 comments
Labels

Comments

@Rocky-Hu
Copy link

 Expression expression = new Expression("a- b");
        expression
                .with("a","480.70")
                .and("b","480.99");
BigDecimal c=  expression.eval();

The result is -0.29. I want is -0.290, and set the precision is not working.

like BigDecimal:

BigDecimal a= new BigDecimal("480.70");
BigDecimal b= new BigDecimal("480.99");
BigDecimal c= a.subtract(b).setScale(3);

Is there any way ?

@RobertZenz
Copy link
Collaborator

Yes, eval() strips the zeroes f the BigDecimal result by default. However, you missed that there is the eval(boolean) overload which allows you to disable that behavior.

@uklimaschewski
Copy link
Collaborator

With version 3, stripping trailing zeroes can be configured, but I see that it isn't in the documentation.
Leaving this open, though it is fixed to remind adding the documentation.

@uklimaschewski
Copy link
Collaborator

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

No branches or pull requests

3 participants