- Trending Categories
- 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
Convert.ToDecimal Method in C#
Convert a specified value to a decimal number using the Convert.ToDecimal() method.
We have a string here.
string stringVal = "2,345.26";
Now, let us use the Convert.ToDecimal() method to convert it to a decimal number.
decimal decimalVal; decimalVal = System.Convert.ToDecimal(stringVal);
Let us now see the complete example −
Example
using System; public class Demo { public static void Main() { decimal decimalVal; string stringVal = "2,345.26"; decimalVal = System.Convert.ToDecimal(stringVal); System.Console.WriteLine("String converted to decimal = {0} ", decimalVal); } }
Output
String converted to decimal = 2345.26
Advertisements