Convert.ToDouble(String, IFormatProvider) Method in C#

CsharpServer Side ProgrammingProgramming

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.


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.


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);


This will produce the following output −

Converted Decimal value...
Published on 06-Nov-2019 10:08:52