1
Vote

Allow to configure CultureInfo

description

I see many posts here about dots and comma as the decimal value separator.

From what I see, it use the current computer cultureinfo. I have a french Windows (,), and work with numbers written in English (.). When sending decimal numbers to NCalc, if the input string is using a dot instead of the comma it crash:

System.FormatException: Le format de la chaîne d'entrée est incorrect.
à System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
à System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
à System.Decimal.Parse(String s)
à NCalc.Numbers.ConvertIfString(Object s)
à NCalc.Numbers.Divide(Object a, Object b)
à NCalc.Domain.EvaluationVisitor.Visit(BinaryExpression expression)
à NCalc.Domain.BinaryExpression.Accept(LogicalExpressionVisitor visitor)
à NCalc.Domain.EvaluationVisitor.<>c__DisplayClass2.<Visit>b__1()
à NCalc.Domain.EvaluationVisitor.Visit(BinaryExpression expression)
à NCalc.Domain.BinaryExpression.Accept(LogicalExpressionVisitor visitor)
à NCalc.Expression.Evaluate()

If I test in a separate project, I can easily reproduce it:
var test = Decimal.Parse("12.3"); <-- crash
var test = Decimal.Parse("12.3", CultureInfo.InvariantCulture); <-- ok

Now, I want to keep using dots in the NCalc strings no matter what the Windows locale is set to, so it would be appreciated to be able to configure it to use the CultureInfo you want that will be used in the NCalc internal functions (in this case, InvariantCulture).

comments