Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 377
RG-3 Avatar asked Apr 06 '11 18:04

RG-3


People also ask

How do you convert a decimal to a double in C?

The Decimal. ToDouble() method can be used to convert a decimal to a double in C#. The Decimal. ToDouble() method converts a specified decimal value to its equivalent double-precision, floating-point number.

How do you convert a decimal to a double?

You can also convert a Decimal to a Double value by using the Explicit assignment operator. Because the conversion can entail a loss of precision, you must use a casting operator in C# or a conversion function in Visual Basic.

How do I convert an int to a double in C#?

To convert a specified value to a double-precision floating-point number, use Convert. ToDouble() method. long[] val = { 340, -200}; Now convert it to Double.


1 Answers

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

decimal x  = 3.141592654M ; double  pi = (double) x ; 
like image 123
Nicholas Carey Avatar answered Oct 07 '22 10:10

Nicholas Carey