2

I am going to implement custom server side validation of numeric user input.

All is what I nee is to be able to feed a formula to the calculator, feed parameters and get the result back.

The formula consist of basic arithmetical operation, for example like this

([name1] + [name2] - [name3])*1.5

Then it should accept parameters like

calculator.AddParam("name1", 12);

And return the result of calculation like

var result = calculator.Calculate();

Does such libriary exist for .net?

v00d00
  • 3,095
  • 3
  • 28
  • 43

3 Answers3

2

I've used Flee a couple times to do this pretty quickly and easily.

Ron Warholic
  • 9,744
  • 27
  • 47
1

Try this

(C# compiling code at runtime)

http://www.codeproject.com/KB/recipes/matheval.aspx

Carter Medlin
  • 10,482
  • 4
  • 55
  • 65
1

You could reuse the Javascript engine that comes with Windows, as explained here: parse and execute JS by C#

It's quite powerful, supports 32-bit and 64-bit architectures, and does not need to be documented, as everyone knows how to write some JS statemements :-)

Community
  • 1
  • 1
Simon Mourier
  • 117,251
  • 17
  • 221
  • 269