问题
I'm developing an Android app that i get an String with the mathematical expression i have to calculate, i did it to convert the letters into the numbers i need, but what is the best way to evaluate this?
Nothing too complicated, the formulas are like those:
((A * 2 + B * 3 + C * 5) / 10) + D
EDIT: Just found that guy, very simple API, works like a charm http://code.google.com/p/symja/wiki/MathExpressionParser
回答1:
You want some sort of math parser.
Fun to roll your own, or there are plenty of hits on google: https://www.google.co.uk/#hl=en&gs_nf=1&cp=16&gs_id=7&xhr=t&q=java+math+parser
来源:https://stackoverflow.com/questions/10704885/evaluate-mathematical-expression-within-string