我目前使用ncalc库来做几次评估,并从中得出结果。ncalc数千格式的逗号无法评估?
现在我发现了一个问题,如果我有格式“1,234.01”的价格,它将无法评估我的表情。
我使用目前的解决方法是删除,
但我想知道是否有方法来评估一种货币,而无需去除,
例如:
decimal price = 0;
if (!decimal.TryParse(iPrice.Text, out price))
{
MessageBox.Show("Price is not formatted correctly...");
return;
}
decimal currency = 0;
if (!decimal.TryParse(iCurrency.Text, out currency))
{
MessageBox.Show("Currency is not formatted correctly...");
return;
}
string formula = iFormula.Text.Replace("Price", price.ToString("n2")).Replace("Currency", currency.ToString("n2"));
Expression exp = new Expression(formula);
exp.Evaluate();
评估失败,因为,
的从我的价格,如果我删除它,它工作得很好。
样品的公式:
(((Price+12,9)+((Price+12,9)*0,05)+(((Price+12,9)+((Price+12,9)*0,05))*0,029)+0,45)*Currency)
堆栈跟踪的要求:
NCalc.EvaluationException was unhandled
Message=mismatched input ',' expecting ')' at line 1:4
mismatched input ',' expecting ')' at line 1:20
mismatched input ',' expecting ')' at line 1:43
mismatched input ',' expecting ')' at line 1:59
missing EOF at ')' at line 1:77
Source=NCalc
StackTrace:
at NCalc.Expression.Evaluate()
听起来像文化问题,或者ncalc不支持默认不变文化。 – leppie
leppie good call我会检查不变... – Guapo
鉴于堆栈跟踪。这肯定是一个文化问题。 – leppie