Saturday 15 May 2010

c# - Operator '/' can't be applied to operands of types 'decimal' and 'double' - NCalc -



c# - Operator '/' can't be applied to operands of types 'decimal' and 'double' - NCalc -

i'm trying run formula in ncalc:

"( abs([a] - [b]) / ( ([a] + [b]) / 2.0 ) ) * 100"

i error:

operator '/' can't applied operands of types 'decimal' , 'double'

the [a] , [b] parameters passed decimals. tried putting 'm' on 2 , 100 so:

"( abs([a] - [b]) / ( ([a] + [b]) / 2m ) ) * 100m"

but throws exception:

additional information: extraneous input 'm' expecting ')' @ line 1:36

i followed this question, didn't help me. same question posted on codeplex no answer. ideas?

possible workaround pass 2m parameter create recognized decimal value, illustration :

string strexp = "( abs([a] - [b]) / ( ([a] + [b]) / [c] ) ) * 100"; look e = new expression(strexp); e.parameters["a"] = 3.5m; e.parameters["b"] = 1m; e.parameters["c"] = 2m; //<- pass 2m look parameter

c# .net exception-handling casting ncalc

No comments:

Post a Comment