C# Decimal to double?

我只是一个虾纸丫 提交于 2019-12-12 03:33:05

问题


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?)  

回答1:


This is because Math.Pow has only one overload - the one accepting two doubles. Since you want to work with decimals, you need to use explicit casts in both directions:

decimal m = (decimal)Math.Pow((double)a, (double)b);


来源:https://stackoverflow.com/questions/35614176/c-sharp-decimal-to-double

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!