I'm making a calculator. It will be very long and hard to do the proper string analizer which parses strings by chars, so I thought, is there a way to turn string into a command line like this:
double num = "12/6+23*4";
I'm making a calculator. It will be very long and hard to do the proper string analizer which parses strings by chars, so I thought, is there a way to turn string into a command line like this:
double num = "12/6+23*4";
There is a small and simple trick to do this. First, import the namespace
using System.Data;
and after that,
string math = "12.0/6+23*4";
decimal value = (decimal)new DataTable().Compute(math, null);
//value = 94.0