如何将字符串字段计算为双精度. [英] How to calculate string fields as double.
本文介绍了如何将字符串字段计算为双精度.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
String res="120*10-50%5";
答案是230.
如何将其解析为double?
我该如何计算?
请帮助我.
The answer is 230.
How can I parse this as double?
How can I calculate this?
Please help me.
推荐答案
您正在寻找的是算术评估函数.
在SO处查看此问题和答案; http://stackoverflow.com/questions/4173623/mathematical-expression-string- to-number-in-java [ ^ ]
有很多关于此的文章,如果您只是四处搜索,也可以使用库.
What you are looking for is Arithmetic Evaluation functions.
See this question and answers over at SO; http://stackoverflow.com/questions/4173623/mathematical-expression-string-to-number-in-java[^]
There are various articles for this and also libraries you could use if you just search around.
看看这篇很棒的CodeProject文章:
通过在运行时编译C#代码来评估数学表达式 [使用muParser解析数学表达式 [ http://muparser.sourceforge.net/ [ ^ ]
Have a look at this great CodeProject article:
Evaluating Mathematical Expressions by Compiling C# Code at Runtime[^]
or this library:
Parsing Mathematical Expressions with muParser[^]
http://muparser.sourceforge.net/[^]
这篇关于如何将字符串字段计算为双精度.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文