Pregunta

I need to solve string equations in an android app, e.g. "3 + 4*(5 - log(100))". I have tried to use BeanShell for this, unfortunately I have some problems with the integer/decimal numbers. When I enter

 Interpreter interpreter = new Interpreter();
 String res = "9223372036854775807D";
 interpreter.eval("result = " + res);
 res = interpreter.get("result").toString();
 res = new BigDecimal(res).stripTrailingZeros().toPlainString();

I get as result 9223372036854776000??

But when I use String res = "9223372036854775807D"; I get the correct 9223372036854775807. I simply cannot suspitude all D to L because then I get wrong results when having somthing like 3L/2L -> 1 (but should be 1.5 Does anyone know how to handle huge numbers such as 9223372036854775807 or -9223372036854775808 or can anyone suggest an alternative to BeanShell?

¿Fue útil?

Solución

Use MathEval download it from this link: http://tech.dolhub.com/code/matheval

Otros consejos

have you tried JEP expression parser?
it is a Good mathematical expression parser purely written in Java and can parse trigonometric,logarithm functions, complex values and you can customize your own functions also...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top