- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decimal.ToDouble() Method in C#
The Decimal.ToDouble() method in C# is used to convert the value of the specified Decimal to the equivalent double-precision floating-point number.
Syntax
Following is the syntax −
public static double ToDouble (decimal val);
Above, Val is the decimal number to convert.
Example
Let us now see an example to implement the Decimal.ToDouble() method −
using System; public class Demo { public static void Main(){ Decimal val1 = -0.22m; Decimal val2 = -0.01m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Double res1 = Decimal.ToDouble(val1); Double res2 = Decimal.ToDouble(val2); Console.WriteLine("Double value1 (Decimal to Double) = "+res1); Console.WriteLine("Double value2 (Decimal to Double) = "+res2); } }
Output
This will produce the following output −
Decimal 1 = -0.22 Decimal 2 = -0.01 Double value1 (Decimal to Double) = -0.22 Double value2 (Decimal to Double) = -0.01
Example
Let us now see another example to implement the Decimal.ToDouble() method −
using System; public class Demo { public static void Main(){ Decimal val1 = 23828m; Decimal val2 = 976587687595766665m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Double res1 = Decimal.ToDouble(val1); Double res2 = Decimal.ToDouble(val2); Console.WriteLine("Double value1 (Decimal to Double) = "+res1); Console.WriteLine("Double value2 (Decimal to Double) = "+res2); } }
Output
This will produce the following output −
Decimal 1 = 23828 Decimal 2 = 976587687595766665 Double value1 (Decimal to Double) = 23828 Double value2 (Decimal to Double) = 9.76587687595767E+17
Advertisements