Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
