执行数学方程式中的Andr​​oid方程式、数学、oid、Andr

由网友(糖ガジ)分享简介:我需要能够处理一个数学公式,如(45 + 9)/ 8,在我的应用程序。我想用JavaScript只是EVAL,但意识到,我不能使用的javax.script中的Andr​​oid。于是,我找到的WebView,但我有一点麻烦使用它。大部分的例子是指使用与JS code外部网页,或者使用的javascript:VAR回报...

我需要能够处理一个数学公式,如(45 + 9)/ 8,在我的应用程序。我想用JavaScript只是EVAL,但意识到,我不能使用的javax.script中的Andr​​oid。于是,我找到的WebView,但我有一点麻烦使用它。大部分的例子是指使用与JS code外部网页,或者使用的javascript:VAR回报...等等我需要使用后者,但我一直有一个有点麻烦与变量回到我的应用程序。

I need to be able to handle a math equation such as "(45+9)/8" in my app. I wanted to just eval it using JavaScript, but realized that I can't use javax.script in Android. So, I found WebView, but I'm having a bit of trouble using it. Most of the examples refer to using an external page with the JS code, or using "javascript: var return ...etc." I'd need to use the latter, but I've been having a bit of trouble with returning the variable to my app.

是否有可能有JS的eval它,然后写的值设置为隐藏的TextView?

Is it possible to have the JS eval it and then write the value to a hidden TextView?

推荐答案

查看 exp4j 。这是一个简单的前pression评估的Java。对于公式,你张贴在你的问题,你可能只是做:

Check out exp4j. It's a simple expression evaluator for java. For the equation you posted in your question you could just do:

Calculable calc = new ExpressionBuilder("(45+9)/8").build()
double result1=calc.calculate();
阅读全文

相关推荐

最新文章