本文介绍了运算符'/'不能应用于类型“decimal”和“double”的操作数 - NCalc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在NCalc中执行这个公式:
I'm trying to run this formula in NCalc:
"( Abs([a] - [b]) / ( ([a] + [b]) / 2.0 ) ) * 100"
错误:
Operator '/' can't be applied to operands of types 'decimal' and 'double'
[a]和[b]参数以小数形式传递。我试着把'm'放在2和100上像这样:
The [a] and [b] parameters are passed as Decimals. I tried putting 'm' on the 2 and 100 like so:
"( Abs([a] - [b]) / ( ([a] + [b]) / 2m ) ) * 100m"
例外:
Additional information: extraneous input 'm' expecting ')' at line 1:36
我随后上,但没有回答。任何想法?
I followed this question, but it didn't help me. The same question posted on codeplex with no answer. Any ideas?
推荐答案
可能的解决方法是将 2m
使其正确识别为十进制
值,例如:
Possible workaround is to pass 2m
as parameter to make it recognized properly as a decimal
value, for example :
string strExp = "( Abs([a] - [b]) / ( ([a] + [b]) / [c] ) ) * 100";
Expression e = new Expression(strExp);
e.Parameters["a"] = 3.5m;
e.Parameters["b"] = 1m;
e.Parameters["c"] = 2m; //<- pass 2m as expression parameter
这篇关于运算符'/'不能应用于类型“decimal”和“double”的操作数 - NCalc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!