是否有关于Android的数学EX pression解析库? [英] Is there a mathematical expression parsing library on Android?

查看:174
本文介绍了是否有关于Android的数学EX pression解析库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我已经在iOS上,我希望端口到Android的应用程序。该应用程序使用的Objective-C GCMathParser 框架/班。

Currently I have an app on iOS that I am looking to port to Android. This app uses the Objective-C GCMathParser framework/class.

我要寻找在Android更换(或方法,使在Android GCMathParser工作),这将是能够计算的东西,如:

I am looking for a replacement on Android (or a way to make GCMathParser work on Android) that would be able to calculate stuff like:

2*2

(2+3)+2

((2+3)+2)/5

(-2 + sqrt((-5^2)-4*2*3))/(2 * 2) 

我想能够养活一个字符串到这个(如上),并得到一个结果,preferably相对precise(如双)。

I would like to be able to feed a String into this (like above) and get back a result, preferably relatively precise (like double).

我有什么选择解析数学EX pressions这样在Android?

What options do I have for parsing mathematical expressions like this on Android?

推荐答案

怎么样的 MVEL

Map vars = new HashMap();
vars.put("x", new Integer(5));
vars.put("y", new Integer(10));

Integer result = (Integer) MVEL.eval("x * y", vars);

您也可以使用它在普通的Java调用,例如的Math.sqrt(...)

You could also use plain Java calls in it like Math.sqrt(...)

这篇关于是否有关于Android的数学EX pression解析库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆