Question

I do have mathematical formulas like,

(3.14*2.500^2)/4

IF(45.0=0,0,1/42.9^2)

Which are formulas derived from Excel formulas.

I need to get result of these kind of formulas using java only.

I come across helpful link.

Can you please advice me for best way doing this?

  1. Do we have anything where we can directly put this formula and get result?
  2. Do I need to Tokanize the string and calculate it using basic Java Math package?
  3. If I have to Tokanize only then which is the best basic Math package or Commons Math?
Was it helpful?

Solution

1) No. Java and most other languages does not have a function to evaluate an expression from a string.

2-3) Yes. You must tokenize it and write your own parser, or just use a library, like the one you posted the link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top