简体   繁体   中英

Converting Decimal to Double in C#?

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!

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

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

You can use decimal's built in converter.

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

Just Try

Decimal yourDecimal = 3.222222m;

Convert.ToDouble(yourDecimal);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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