在系統中須要計算公式,參數能夠配置,相似excel的狀況,能夠實現數據的計算。git
實例github
public static void main(String[] args) throws InterruptedException { Argument days = new Argument("days = 30"); Expression min = new Expression("min(days/10,1)", days); mXparser.consolePrint(min.getExpressionString() + "----" + min.calculate()); Expression e = new Expression("2-(32-4)/(23+4/5)-(2-4)*(4+6-98.2)+4"); mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate()); Expression abs = new Expression("abs(-1)"); mXparser.consolePrintln("Res: " + abs.getExpressionString() + " = " + abs.calculate()); Expression sqrt = new Expression("sqrt(2)"); mXparser.consolePrintln("Res: " + sqrt.getExpressionString() + " = " + sqrt.calculate()); Function A = new Function("t(a,b) = 1/2 * a *b"); Expression expression = new Expression("t(2,4)",A); mXparser.consolePrintln(expression.getExpressionString() +"-----------"+expression.calculate()); Argument a = new Argument("a = 3"); Argument b = new Argument("b = 3"); Argument h = new Argument("h = 4"); Expression expression1 = new Expression("t(b,h)",A,b,h,a); mXparser.consolePrintln(expression1.getExpressionString() +"-----------"+expression1.calculate()); Expression expression2 = new Expression("1/2 * a *b",A,b,h,a); mXparser.consolePrintln(expression2.getExpressionString() +"-----------"+expression2.calculate()); }
https://github.com/mariuszgromada/MathParser.org-mXparserexpress