Why can't I use math.pow
with numericUpDown
value? When I use this code:
a = (numericUpDown1.Value);
b = (numericUpDown2.Value);
m = Math.Pow(a, b);
I receive the following error:
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?)
This is because Math.Pow
has only one overload - the one accepting two double
s. Since you want to work with decimal
s, you need to use explicit casts in both directions:
decimal m = (decimal)Math.Pow((double)a, (double)b);