C# | Double.ToString() Method | Set - 2 - GeeksforGeeks

21 Oct, 2021
Double.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: 
ToString(String) Method
ToString() Method
ToString(IFormatProvider) Method
ToString(String, IFormatProvider) Method
Here, we will discuss the last two methods. 
This method is used to convert the numeric value of the current instance to its equivalent string representation using the specified culture-specific format information.Syntax: 
public string ToString (IFormatProvider provider);
Parameters: This method takes an object of type IFormatProvider which supplies culture-specific formatting information.Return Value: This method returns the string representation of the value of the current instance in the format specified by the provider parameter.Example: 
csharp
// C# program to demonstrate// Double.ToString(IFormatProvider)// Methodusing System;using System.Globalization; class GFG {     // Main Method    public static void Main()    {        // declaring and initializing Double value        double d1 = 568912.4587d;         // creating and initializing        // the object of CultureInfo        CultureInfo provider = new CultureInfo("en-us");         // using the method        string value = d1.ToString(provider);         // Display the value        Console.WriteLine("The Value is {0} and provider is {1}",                                           value, provider.Name);    }}
The Value is 568912.4587 and provider is en-US
 
This method is used to convert the numeric value of the current instance to its equivalent string representation using the specified format and culture-specific formatting information.Syntax:  
public string ToString (string format, IFormatProvider provider);
Parameters:  
format: It is a numeric format string. provider: It is an object that supplies culture-specific formatting information.  
Return Value: This method returns the string representation of the value of the current instance in the format specified by the provider parameter.Example: 
csharp
// C# program to demonstrate the// Double.ToString(String, IFormatProvider)// Methodusing System;using System.Globalization; class GFG {     // Main Method    public static void Main()    {         // declaring and initializing Double value        double d1 = 7876312.7823d;         // creating and initializing        // the object of CultureInfo        CultureInfo provider = new CultureInfo("fr-FR");         // declaring and initializing format        string format = "E04";         // using the method        string val = d1.ToString(format, provider);         // Displaying the details        Console.WriteLine("The value is {0}",val);        Console.WriteLine("The Format is {0}",format);        Console.WriteLine("The Provider is {0}", provider.Name);    }}
The value is 7,8763E+006
The Format is E04
The Provider is fr-FR
 
Reference:  
https://docs.microsoft.com/en-us/dotnet/api/system.double.tostring?view=netframework-4.7.2
 
sagartomar9927
CSharp-Double-Struct
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
C# | Delegates
C# | Method Overriding
C# | Abstract Classes
Difference between Ref and Out keywords in C#
Extension Method in C#
C# | Replace() Method
C# | Class and Object
C# | Constructors
Introduction to .NET Framework