Reputation: 107
I've a dropdown like this
@Html.DropDownList("Operator", new List<SelectListItem>
{
new SelectListItem() {Text = "/", Value = "/", Selected = true},
new SelectListItem() {Text = "*", Value = "*"},
new SelectListItem() {Text = "+", Value = "+"},
new SelectListItem() {Text = "-", Value = "-"}
}, new {@Class = "form-control", @Id = "Operator"})
In my action method I want to use var1 Operator var2. Suppose 10 Operator 15 = 25 when Operator = "+" Is it possible?
Upvotes: 2
Views: 2157
Reputation: 1216
Recently I was using open-source library for parsing math expressions provided as strings. The parser / evaluator name is mXparser.
Example:
Expression e = new Expression("2+3/(4+1)");
double v = e.calculate();
Additionally - this software is using mXparser as well - you can learn the syntax Scalar Calculator app.
Best regards
Upvotes: 3