The Convert.ToDouble() method in C# converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.
Syntax
Following is the syntax −
public static double ToDouble (string val, IFormatProvider provider);
Above, the value value is a string that contains the number to convert, whereas the provider is an object that supplies culture-specific formatting information.
Example
Let us now see an example to implement the Convert.ToDouble() method −
using System;
using System.Globalization;
public class Demo {
public static void Main(){
String val = "876876, 878";
NumberFormatInfo formatProvider = new NumberFormatInfo();
formatProvider.NumberDecimalSeparator = ", ";
formatProvider.NumberGroupSeparator = ".";
formatProvider.NumberGroupSizes = new int[] { 2 };
Console.WriteLine("Converted Decimal value...");
double res = Convert.ToDouble(val, formatProvider);
Console.Write("{0}", res);
}
}Output
This will produce the following output −
Converted Decimal value... 876876.878