RG-3
RG-3

Reputation: 6188

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!

Upvotes: 73

Views: 114357

Answers (3)

Chuck Savage
Chuck Savage

Reputation: 11945

You can use decimal's built in converter.

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

Upvotes: 43

anishMarokey
anishMarokey

Reputation: 11397

Just Try

Decimal yourDecimal = 3.222222m;

Convert.ToDouble(yourDecimal);

Upvotes: 17

Nicholas Carey
Nicholas Carey

Reputation: 74177

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

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

Upvotes: 110

Related Questions