diff --git a/VAR.ExpressionEvaluator.Tests/ParserTests.cs b/VAR.ExpressionEvaluator.Tests/ParserTests.cs index c142532..31d59af 100644 --- a/VAR.ExpressionEvaluator.Tests/ParserTests.cs +++ b/VAR.ExpressionEvaluator.Tests/ParserTests.cs @@ -864,6 +864,17 @@ namespace VAR.ExpressionEvaluator.Tests Assert.False((bool?)result); } + [Fact()] + public void Misc__ProductWithStringDecimals_EqualsFalse() + { + EvaluationContext evaluationContex = new EvaluationContext(); + evaluationContex.SetVariable("$1109", "1933"); + evaluationContex.SetVariable("$1150", "02.00000"); + string expression = "$1109 * $1150"; + object result = Parser.EvaluateString(expression, evaluationContex); + Assert.Equal(3866.00000M, result); + } + #endregion Misc } } \ No newline at end of file diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionDivisionNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionDivisionNode.cs index 62c04a3..68f93bf 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionDivisionNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionDivisionNode.cs @@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator if (leftValue is string) { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator } if (rightValue is string) { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionEqualsNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionEqualsNode.cs index f27c703..64ef60a 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionEqualsNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionEqualsNode.cs @@ -44,7 +44,7 @@ // Decimal if (leftValue is string) { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { leftValue = null; } @@ -55,7 +55,7 @@ } if (rightValue is string) { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { rightValue = null; } @@ -85,7 +85,7 @@ return null; } decimal decValue; - if (decimal.TryParse(text, out decValue)) + if (decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decValue)) { return decValue != 0; } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterOrEqualThanNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterOrEqualThanNode.cs index d538486..0c8b18a 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterOrEqualThanNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterOrEqualThanNode.cs @@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterThanNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterThanNode.cs index 02d1800..9470d41 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterThanNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionGreaterThanNode.cs @@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessOrEqualThanNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessOrEqualThanNode.cs index 703bedd..9a84087 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessOrEqualThanNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessOrEqualThanNode.cs @@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessThanNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessThanNode.cs index 37ea31b..c92ebf8 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessThanNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionLessThanNode.cs @@ -24,7 +24,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -39,7 +39,7 @@ namespace VAR.ExpressionEvaluator } else { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMinusNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMinusNode.cs index 9264bcf..6b83697 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMinusNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMinusNode.cs @@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator if (leftValue is string) { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator } if (rightValue is string) { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMultiplyNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMultiplyNode.cs index b9dbb1f..af431c5 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMultiplyNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionMultiplyNode.cs @@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator if (leftValue is string) { - if (decimal.TryParse((string)leftValue, out decimal dec) == false) + if (decimal.TryParse((string)leftValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)leftValue)); } @@ -26,7 +26,7 @@ namespace VAR.ExpressionEvaluator } if (rightValue is string) { - if (decimal.TryParse((string)rightValue, out decimal dec) == false) + if (decimal.TryParse((string)rightValue, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)rightValue)); } diff --git a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionNumberNegateNode.cs b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionNumberNegateNode.cs index cd70aba..ae50713 100644 --- a/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionNumberNegateNode.cs +++ b/VAR.ExpressionEvaluator/ExpressionNodes/ExpressionNumberNegateNode.cs @@ -18,7 +18,7 @@ namespace VAR.ExpressionEvaluator if (value is string) { - if (decimal.TryParse((string)value, out decimal dec) == false) + if (decimal.TryParse((string)value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out decimal dec) == false) { throw new Exception(string.Format("Can't convert to decimal string value \"{0}\"", (string)value)); } diff --git a/VAR.ExpressionEvaluator/Parser.cs b/VAR.ExpressionEvaluator/Parser.cs index 055a089..c6744e5 100644 --- a/VAR.ExpressionEvaluator/Parser.cs +++ b/VAR.ExpressionEvaluator/Parser.cs @@ -32,7 +32,7 @@ namespace VAR.ExpressionEvaluator #region Creator - private ITokenizer _tokenizer; + private readonly ITokenizer _tokenizer; public Parser(ITokenizer tokenizer) {