Converting Decimal to Double in C#?

C#.NetDoubleDecimal

C# Problem Overview


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!

C# Solutions


Solution 1 - C#

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

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

Solution 2 - C#

You can use decimal's built in converter.

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

Solution 3 - C#

Just Try

Decimal yourDecimal = 3.222222m;

Convert.ToDouble(yourDecimal);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRG-3View Question on Stackoverflow
Solution 1 - C#Nicholas CareyView Answer on Stackoverflow
Solution 2 - C#Chuck SavageView Answer on Stackoverflow
Solution 3 - C#anishMarokeyView Answer on Stackoverflow