I use the third-party library org.nfunk.jep . But all calculations inside this library are made in double , regardless of what type the input variables had, since the addVariable method in the JEP class can only accept variables of the following types as input:

enter image description here

For example, when I execute the following code:

 BigDecimal value1 = new BigDecimal("29250.24"); BigDecimal value2 = new BigDecimal("263.21"); JEP calc = new JEP(); calc.addVariable("var1", Double.parseDouble(value1)); calc.addVariable("var2", Double.parseDouble(value2)); calc.parseExpression("var1 - var2"); System.out.println("Результат: " + calc.getValue()); 

I want to get "28987.03", but in reality the output is:

Result: 28987.0300000002

Maybe someone knows how to work with this library and BigDecimal or knows similar libraries that work with BigDecimal type numbers?

    1 answer 1

    Write a function that will produce a number from the above number, so there will be 2 digits after the decimal point.