This documentation is archived and is not being maintained.

Double.ToString Method (IFormatProvider)

Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

No code example is currently available or this language may not be supported.
public final String ToString (
	IFormatProvider provider
public final function ToString (
	provider : IFormatProvider
) : String
Not applicable.



An IFormatProvider that supplies culture-specific formatting information.

Return Value

The string representation of the value of this instance as specified by provider.

The return value can be PositiveInfinitySymbol, NegativeInfinitySymbol, NaNSymbol, or a string of the form:


Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.


A negative sign or positive sign symbol.


A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits.


A culture-specific decimal point symbol.


A series of digits specifying the fractional part of the number.


A lowercase character 'e', indicating exponential (scientific) notation.


A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45e+6", "500", "3.1416", "600", "-0.123", and "-Infinity".

This instance is formatted with the general numeric format specifier ("G").

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The provider parameter is an IFormatProvider instance that obtains a NumberFormatInfo object that supplies culture-specific format information. If provider is a null reference (Nothing in Visual Basic), the return value is formatted with NumberFormatInfo data for the current culture.

The following code example formats an integral and a floating-point numeric value using the thread current culture, a specified culture, and all the standard numeric format specifiers. This code example uses two particular numeric types, but would yield similar results for any of the numeric base types (Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Decimal, Single, and Double).

No code example is currently available or this language may not be supported.

The following code example illustrates the use of ToString, taking a String and an IFormatProvider as parameters:

public class Temperature implements IFormattable {
    /// <summary>
    /// IFormattable.ToString implementation.
    /// </summary>
    public function ToString(format : String, provider : IFormatProvider) : String {
        if( format != null ) {
            if( format.Equals("F") ) {
                return String.Format("{0}'F", this.Value.ToString());
            if( format.Equals("C") ) {
                return String.Format("{0}'C", this.Celsius.ToString());

        return m_value.ToString(format, provider);

    // The value holder
    protected var m_value : double;

    public function get Value() : double{
        return m_value;
            public function set Value(value : double) {
        m_value = value;

    public function get Celsius() : double {
        return (m_value-32.0)/1.8;
            public function set Celsius(value : double) {
        m_value = 1.8*value+32.0;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0