e.g.
Converting between radians and degrees, 7 Pi radians = 1260 degrees
User input for radians.
Trying to convert a user input string "Pi" to Math.Pi, to calculate.
e.g.
Converting between radians and degrees, 7 Pi radians = 1260 degrees
User input for radians.
Trying to convert a user input string "Pi" to Math.Pi, to calculate.
EDIT:
Looks like you need to strip the string out and then use a formula.
Something like:
const string pi = "pi";
var input = "7pi";
var containsPi = (input.IndexOf(pi) > -1)
var inputDecimal = Convert.ToDecimal(input.Replace(input, pi, ""));
if (containsPi ) inputDecimal = inputDecimal * Math.Pi;
var resultInDegreees = inputDecimal * 180.0 / Math.Pi;
That depends on the input you allow the user.
If it's just something like 0.5 Pi
or 3 Pi
and you want the actual value for it, you can simply remove the Pi
part from the input string, parse the remaining string into a number and multiply it with Math.PI
Regex pi = new Regex(@"\s*pi\s*", RegexOptions.IgnoreCase);
var v = pi.Replace(input, "");
double d = Convert.ToDouble(v);
double rad = d * Math.Pi;
If you have more complex inputs like 3/4 Pi
or even more complex formulas, you'll need some sort of formula-interpreter. Many of them would be able to deal with constants like Pi.