Java中的数学表达式(字符串)转数字
我试图找到类似 Java Embedding Plugin (JEP) 的东西,它可以评估数学公式(字符串)并返回答案。
但它也应该计算一个变量,例如: (25+36+x)*2 = 25 应该给出: x = -11
有点像 http://www.wolframalpha.com/,但它不应该那么通用,它应该可以离线工作。
开源是首选。
我的小计算器项目 http://sourceforge.net/projects/calex/ 需要它。
I'm trying to find something like Java Embedding Plugin (JEP) that can evaluate a mathematical formula (string) and give back the answer.
But it should also calculate a variable, for example: (25+36+x)*2 = 25 should give: x = -11
A little like http://www.wolframalpha.com/, but it shouldn't be that versatile, and it should work off-line.
Open source is preferred.
I need it for my little calculator project, http://sourceforge.net/projects/calex/.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这称为
算术评估
。实现此目的的最简单方法之一是使用 Edsger Dijkstra Shunting-yard_algorithm。但我在一些 stackoverflow 用户博客上看到了您正在寻找的确切解决方案,但我不记得地址了(就像“代码猴子主义”)。它是轻量级类,您可以在小程序中使用它(您还可以定义常量和重置值)。
编辑:找到它:http://tech.dolhub.com/Code/数学评估
This is called
Arithmetic evaluation
. One of the easiest way to implement this is using Edsger Dijkstra Shunting-yard_algorithm.But I have seen exact solution what you are looking for on some stackoverflow user blog, but I can't remember the address (it was like 'code monkeyism'). It was lightweight class, that you could use in applets (you could also define constants and reset values).
Edit: Found it: http://tech.dolhub.com/Code/MathEval
我根据 Dijkstra 的 Shunting Yard 算法发布了一个表达式求值器,遵循 Apache 许可证 2.0:
http://projects.congrace.de/exp4j/index.html
I released an expression evaluator based on Dijkstra's Shunting Yard algorithm, under the terms of the Apache License 2.0:
http://projects.congrace.de/exp4j/index.html