I used jeval for some data computing tasks, and found a loss of accuracy. Is there any way to avoid accuracy loss while using jeval? I want to get the accurate result just like BigDecimal.
public class EvalTest {
private static Evaluator eva = new Evaluator();
public static void main(String[] args) {
try {
String formula = "780.0000000-259.9999998";
String res = eva.evaluate(formula);
BigDecimal a = BigDecimal.valueOf(780.0000000);
BigDecimal b = BigDecimal.valueOf(259.9999998);
BigDecimal c = a.subtract(b);
System.out.println("a");
} catch (Exception e) {
e.printStackTrace();
}
}
}
If I use jeval, the formula "780.0000000-259.9999998" will get an result as "520.0000001999999", but if I use BigDecimal, I can get the accuracy result "520.0000002".