Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

How to calculate use BigDecimal? #18

Open
xjl456852 opened this issue Jul 26, 2018 · 1 comment
Open

How to calculate use BigDecimal? #18

xjl456852 opened this issue Jul 26, 2018 · 1 comment

Comments

@xjl456852
Copy link

calculate the following,the result is wroing
Scope scope = new Scope();
Variable a = scope.create("a");
Expression expr = Parser.parse("a + 2.4", scope);
a.setValue(1.2);
double evaluate = expr.evaluate();
System.out.println(evaluate);

the result is 3.5999999999999996

How to calculate use BigDecimal , then result is 3.6 ?

@elmuerte
Copy link

You cannot. I've created a fork which uses BigDecimal instead of double as its basis: bdparsii
Using BigDecimal does have its price, it's about 10 times slower to perform the calculations. That's simply the due to the arbitrary precision of BigDecimals, the rest of parsii's fastness is still there.

Note, the port is not production tested, requires java 8 and brings in a dependency: obermuhlner's big-math.

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

No branches or pull requests

2 participants