Math.Pow gives “Cannot implicitly convert type 'double' to 'float' ” error

前端 未结 4 807
暖寄归人
暖寄归人 2021-01-21 12:23

In this program I am trying to create a simple calculator. However, I can\'t seem to find a way to overcome the aforementioned error when reaching the Math.Pow line

4条回答
  •  时光取名叫无心
    2021-01-21 13:25

    Math.Pow uses a double argument. As the error says, there is no implicit conversion from double to float, so convert the result explicitly to float:

    power = (float)Math.Pow(x, 2);
    

    EDIT
    corrected the conversion order

提交回复
热议问题