我试图在我的应用程序中使用nCalc,但由于某种原因,我遇到了想要转换为UInt16的问题,并导致了错误。
string evalstring = "-.503937 ^ 2";
Expression e = new Expression(evalstring);
this.Value = Convert.ToDouble(e.Evaluate());这抛出了;
System.OverflowException occurred
HResult=-2146233066
Message=Value was either too large or too small for a UInt16.
Source=mscorlib
StackTrace:
at System.Convert.ToUInt16(Int32 value)
InnerException: 发布于 2016-07-24 05:00:50
在NCalc表达式中,^是按位异或运算符,它接受两个无符号16位整数操作数。在您的表达式中,NCalc尝试将-.503937转换为UInt16值,并抛出OverflowException,因为该数字小于零。
如果需要求幂,请改用Pow函数:
string evalstring = "Pow(-.503937, 2)";https://stackoverflow.com/questions/38545490
复制相似问题