Convert.ToDouble(String, IFormatProvider) Method in C#
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 −
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.
Todouble c что это
This method is used to converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.
Syntax:
public static double ToDouble (string value, IFormatProvider provider);
Parameters:
- value: It is a string that contains the number to convert.
- provider: It is an object that supplies culture-specific formatting information.
Return Value: This method returns a double-precision floating-point number which is equivalent to the number in value, or 0 (zero) if value is null.
Convert String to Double in C#
Strings are used to store text, and in C#, Strings are not just pieces of text. They are objects that can have several different operations.
A Double is a floating-point number with a decimal value of 15 digits. It is used after Float, another floating-point data type, but limited to just 7 decimal digits.
Often, a String may contain a number in text that may need to be used as a number data type such as; Int, Float, Double, etc., for arithmetic operations.
This article will demonstrate how to convert a String into a Double.
Use the Convert.ToDouble() Function to Convert String to Double in C#
We declare a String variable here and then call the ToDouble() function from the Console class to convert the type String to a Double.
If the above conversion produces an error in rare cases, you may try changing the . to , .
For example, 123.98732 would be converted to 123,98732 . However, chances of this happening are rare, and if an error emerges, you are better off trying the different options given below.
Use the Double.Parse() Method to Convert String to Double in C#
This method is inherited from the class Double and serves as an excellent alternative to the method provided by the Console class. It parses the number from the string and provides a Double data type result.
Use the Double.TryParse() Method to Test and Convert String to Double in C#
The Parse() method comes along with a similar function known as TryParse() . A method that also allows checking if the string is a valid Double or not, along with returning the parsed Double data type.
TryParse() is a Boolean method that returns True if the string is a valid Double and False if it is not. It also takes a second parameter passed by reference to modify its value with the Double parsed from the string.
Remember to always use the out keyword with the second argument passed. Why?
The out keyword in C# passes the argument by reference rather than by value, allowing the function to modify its value and test its validity.
Hello, I am Bilal, a research enthusiast who tends to break and make code from scratch. I dwell deep into the latest issues faced by the developer community and provide answers and different solutions. Apart from that, I am just another normal developer with a laptop, a mug of coffee, some biscuits and a thick spectacle!
Convert String to Double in C#
By
Priya Pedamkar

Introduction to Convert String to Double in C#
In C#, almost all types of data can be converted to any other type. In the same way, we can convert a string to double using a method present inside the “Convert” class called ToDouble() method. There are many overloaded forms of this method and among those overloaded forms, we have two forms to convert a string representation of a number to its equivalent double-precision floating-point number.
Those two overloaded forms are as follows:
Web development, programming languages, Software testing & others
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
- ToDouble(String);
- ToDouble(String, IFormatProvider);
Both these methods return a double value after converting the string value to double.
Syntax with Explanation:
The syntax of Convert.ToDouble() method in both its overloaded forms for converting a string to double is as follows:
In the above syntax, ToDouble() method takes one argument of type string (strValue) which is nothing but a string containing a number to convert to double.
In the above syntax, ToDouble() method takes two arguments; the first is the string representation of a number which needs to be converted to double and second is an object which provides culture-specific formatting information. After conversion both these methods return the equivalent double value for the string passed as the argument.
How to Convert String to Double in C#?
In C#, the “System” namespace contains a class called “Convert” which contains the ToDouble() method in many overloaded forms to convert the specified type of data to its equivalent double value. Among these overloaded forms, two forms allow us to convert a string representation of a number to its equivalent double-precision floating-point number.
These two forms are as follows:
1. ToDouble(String);
Let us understand the working of the above method with the help of the below example:
In the above statement, we have passed a number i.e. “855.65” as a string to ToDouble() method which will be converted to double by the method and the resulted value will be stored in a variable of type double (doubleVal).
2. ToDouble(String, IFormatProvider);
Let us now understand the working of the above method with the help of the below example:
In the above statements, we first created an object of IFormatProvider using the class NumberFormatInfo which implements IFormatProvider. Then, we set some important properties for this object like NumberDecimalSeparator and NumberGroupSeparator.
- NumberDecimalSeparator is used to get or set a string that can be used as the decimal separator in numeric values.
- NumberGroupSeparator is used to get or set a string that separates groups of digits at the left of the decimal in numeric values.
- Now, Convert.ToDouble() method will convert the given string to double using the formatting information provided by the object of NumberFormatInfo and the resultant value will be stored in the variable “doubleVal”.
- If the value of the string in both of the above methods is “null” then these methods will return zero.
- In C#, there exists another common way of converting a string to double which can be done by using Double.Parse() method and Double.TryParse() method.
- Double.Parse(String) method works similarly to Convert.ToDouble() method as it takes a string representation of a number as an argument and converts it to a double-precision floating-point number. The difference is that if the string is “null” then this method does not return zero instead it returns ArgumentNullException.
- Double.TryParse(String, Double) method works the same as Double.Parse() method except it returns a Boolean value which indicates whether the conversion has been done successfully or not. On success, it returns true and the respected double value gets stored in the ‘out’ parameter.
Examples of Convert String to Double in C#
Example showing the conversion of string to double using Convert.ToDouble() method.
Example #1
Code:
Output:

Example #2
Example showing the conversion from string to double using Double.TryParse() method.
Code:
Output:

Example #3
Example showing scenario when the string to be converted to double is either ‘null’ or empty.
Code:
Output:

Conclusion
- String value can be converted to double using Convert.ToDouble() or Double.Parse() method.
- These methods take string representation of a number as input and return its equivalent double-precision floating-point number.
- Both these methods return FormatException if the string argument doesn’t represent the number in a valid format.
Recommended Articles
This is a guide to Convert String to Double in C#. Here we also discuss the Introduction and how to convert string to double in c#? along with different examples and its code implementation. You may also have a look at the following articles to learn more –