简体   繁体   English

C#十进制要翻倍?

[英]C# Decimal to double?

Why can't I use math.pow with numericUpDown value? 为什么我不能将math.pownumericUpDown值一起使用? 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. 这是因为Math.Pow只有一个重载 -一个重载两个double Since you want to work with decimal s, you need to use explicit casts in both directions: 由于要使用decimal s,因此需要在两个方向上使用显式强制转换:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM