dynamicexpresso / DynamicExpresso

C# expressions interpreter
http://dynamic-expresso.azurewebsites.net/
MIT License
1.91k stars 364 forks source link

wrong calc #290

Closed Ramin9072 closed 1 year ago

Ramin9072 commented 1 year ago

hello When it comes to these numbers in calculations, we face errors in the calculation this is a my numbers 115804936*20/100 Result must be 23160987.2 but in class and live code http://dynamic-expresso.azurewebsites.net/ Result is -19788685

metoule commented 1 year ago

You can use the SetDefaultNumberType method to force the interpreter to consider all numbers as double:

var interpreter = new DynamicExpresso.Interpreter();
interpreter.SetDefaultNumberType(DynamicExpresso.DefaultNumberType.Double);

var result = interpreter.Eval<double>("115804936*20/100");
Console.WriteLine(result);

Otherwise, all numbers are considered as integers and you're facing an integer overflow.

Ramin9072 commented 1 year ago

Cool that's work