Is there a string math evaluator in .NET?

前端 未结 16 1416
长情又很酷
长情又很酷 2020-11-22 01:01

If I have a string with a valid math expression such as:

String s = \"1 + 2 * 7\";

Is there a built in library/function in .NET that will p

16条回答
  •  长情又很酷
    2020-11-22 01:37

    I implemented an expression parser a few years ago and had published a version of it in GitHub and Nuget:Albatross.Expression recently. It contains a ExecutionContext class that can evaluate a set of expressions such as:

    • MV = Price * Qty;
    • Price = (Bid + Ask)/2;
    • Bid = .6;
    • Ask = .8;

    It also has built in circular reference check which is useful to avoid a stack overflow.

提交回复
热议问题