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 −
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); } }
String converted to decimal = 2345.26