I want to make tiny calculator that if you write for example 2/3 and you have got 0.6666667. I use DynamicExpresso.Core library but I need to write 2f/3f to have 0.6666667 (if I write 2/3 I get 0). I think I should use somethink like forCounting = Regex.Replace(forCounting, Regex.Match(forCounting, @"\d+").Value, Regex.Match(forCounting, @"\d+").Value + "f");
but it adds f after only first number. Do you have any ideas?
Replace numbers in string to numbers + "f"
137 Views Asked by Kuba_Z2 At
3
There are 3 best solutions below
0

Starting with DynamicExpresso 2.6.0, it's possible to set a default numeric type.
For example, you can ask it to consider all numbers as double, and get the result you expect:
var target = new Interpreter();
target.SetDefaultNumberType(DefaultNumberType.Double);
var dbl = target.Eval<double>("2/3");
Console.WriteLine(dbl); // 0.6666666666666666
Use
See C# proof.
Results:
Text: 2f/3f, 1.9f