Your variables are float
, but the method Math.Pow
returns a double
. Hence you need explicit conversion to be performed on the result of the method.
presentValue = futureValue / (float)Math.Pow(1 + rate, years);
Note: Math.Pow
also takes double
as parameters, but still it works. That’s because implicit conversion is taking place. Because double
can represent every possible value of a float
but reverse isn’t true.
Read about Implicit
and Explicit
conversions
0
solved Cannot implicitly convert type ‘double’ to ‘float’ with Math.Pow()