Converting Decimal to Double in C#?

邮差的信 提交于 2019-12-03 14:20:59

问题


I have a variable which is storing as decimal:

decimal firststYrComp = Int16.Parse(tb1stYr.Text.ToString());

Now I have this to get typecasted into Double? How do I do that? Thanks!


回答1:


You answered your own question—Just cast it to a double:

decimal x  = 3.141592654M ;
double  pi = (double) x ;



回答2:


You can use decimal's built in converter.

decimal decimalValue = 5; 
double doubleValue = decimal.ToDouble(decimalValue);



回答3:


Just Try

Decimal yourDecimal = 3.222222m;

Convert.ToDouble(yourDecimal);


来源:https://stackoverflow.com/questions/5571485/converting-decimal-to-double-in-c

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