codingseb / ExpressionEvaluator

A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts
MIT License
595 stars 99 forks source link

Can't handle division #156

Closed DennisSkoko closed 1 year ago

DennisSkoko commented 1 year ago

Don't know which other cases will not work but I've discovered that 2 * (1 / 5) doesn't work since it evaluates 0. But it is able to handle 2 * 0.2 fine. I've also tried 1 / 5 * 2.

When I discovered this, I tried updating to latest version and also testing in an isolated environment in here: https://dotnetfiddle.net/up4x3W but with no luck.

DennisSkoko commented 1 year ago

After looking into your source code, I managed to understand your package more and now understand that I must specify that those numbers are floats in order to make it work. E.g. 1 / 2 won't work either, must be 1f / 2f.

DennisSkoko commented 1 year ago

In case someone is in the same situation as me where assigning f, d or m in order to make division work. There is an option where all numbers in the expression that doesn't have a decimal will be treated at decimal. OptionForceIntegerNumbersEvaluationsAsDoubleByDefault.