C-锐数学问题与平方根 [英] C-sharp math issue with square root
问题描述
如何评估一个字符串下面前pression一个答案作为一个整数?
How do i Evaluate the following expression from a string to a answer as an integer?
前pression:
√(7+74) + √(30+6)
我是不是要像Sqroot(7 + 74)和Sqroot参数中的每一个(30 + 6)评价还是可以评估整个前pression。任何想法?
Do i have to evaluate each one of the parameters like Sqroot(7+74) and Sqroot(30+6) or is it possible to evaluate the whole expression. Any ideas?
推荐答案
如果该字符串是用户提供的(或无论如何只能在运行时),你需要的是一个数学前pressions解析器(也许更换√字符在文本开方
或任何解析器字符串喂养它之前喜欢)。有在网上提供很多免费的,我个人使用 info.lundin.math 几次都没有任何问题。
If this string is user-supplied (or anyway available only at runtime) what you need is a mathematical expressions parser (maybe replacing the √ character in the text with sqrt
or whatever the parser likes before feeding the string to it). There are many free ones available on the net, personally I used info.lundin.math several times without any problem.
您的问题简单的例子:
info.lundin.Math.ExpressionParser parser = new info.lundin.Math.ExpressionParser();
double result = parser.Parse("sqrt(7+74)+sqrt(30+6)", null);
(在网站上,你可以找到与可通过编程方式指定例如参数更复杂的例子)
(on the site you can find more complex examples with e.g. parameters that can be specified programmatically)
这篇关于C-锐数学问题与平方根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!