简体   繁体   English

如何在j2me midp 2.0中评估基于字符串的公式?

[英]how to evalute String based formulas in j2me midp 2.0?

I working in j2me(midp2.0) platform.I have received a formula String from a server like status=completed-defects along with table data. 我在j2me(midp2.0)平台上工作。我已经从服务器收到了一个状态为String的公式字符串,例如status = completed-defects以及表数据。

the above status, completed, defects are table columns.so,in the status column i want to put the above formula.So, for doing this, i can able to get the value of the completed and defect column and modified the above formula as "=50-40".now i want to evaluate this Strings.Does anybody having the solution to please guide me to get this problem... 上面的状态,完成的缺陷是表列。因此,我要在状态列中输入上面的公式。因此,为此,我可以获取completed和缺陷列的值并将上面的公式修改为“ = 50-40”。现在我要评估此Strings。是否有人有解决方法请指导我解决此问题...

Operators are fixed : + , - , * , / , % , ( , ) and there is no limit for operators. 运算符是固定的:+,-,*,/,%,(,),并且运算符没有限制。

Java Math Expression Evaluator makes exactly what you need. Java Math Expression Evaluator完全满足您的需求。 It supports following functions: +, -, *, /, ^, %, cos, sin, tan, acos, asin, atan, sqrt, sqr, log, min, max, ceil, floor, abs, neg, rndr. 它支持以下功能:+,-,*,/,^,%,cos,sin,tan,acos,asin,atan,sqrt,sqr,log,min,max,ceil,floor,abs,neg,rndr。

Sample: 样品:

MathEvaluator m = new MathEvaluator("-5-6/(-2) + sqr(15+x)");
m.addVariable("x", 15.1d);
System.out.println( m.getValue() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM