-1

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?
Community
  • 1
  • 1
Ketan Bhavsar
  • 5,338
  • 9
  • 38
  • 69
  • Why negative? Any reason? – Ketan Bhavsar Jan 22 '14 at 14:42
  • possible duplicate of [free Java library for evaluating math expressions](http://stackoverflow.com/questions/7258538/free-java-library-for-evaluating-math-expressions) – Eel Lee Jan 22 '14 at 14:54
  • possible duplicate of [convert spreadsheet formulas to java](http://stackoverflow.com/questions/2043614/convert-spreadsheet-formulas-to-java) – andand Jan 22 '14 at 14:55
  • start by writing in java if is lower case. I usually write out my if statements so I can see the indentations. if(a=45){b=0;} else {b = 90;} – danny117 Jan 23 '14 at 00:36

1 Answers1

1

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.