ToString Method (String, IFormatProvider)
Collapse the table of content
Expand the table of content

Decimal.ToString Method (String, IFormatProvider)

 

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

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

abstract ToString : 
        format:string *
        provider:IFormatProvider -> string
override ToString : 
        format:string *
        provider:IFormatProvider -> string

Parameters

format
Type: System.String

A numeric format string (see Remarks).

provider
Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: System.String

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

Exception Condition
FormatException

format is invalid.

The ToString(String, IFormatProvider) method formats a Double value in a specified format of a specified culture. If you want to use default format or culture settings, use the other overloads of the ToString method, as follows:

To use format

For culture

Use the overload

Default ("G") format

Default (current) culture

ToString()

Default ("G") format

A specific culture

ToString(IFormatProvider)

A specific format

Default (current) culture

ToString(String)

The format parameter can be any valid standard numeric format specifier except for D, R, and X, as well as any combination of custom numeric format specifiers. If format is null or an empty string, the return value for 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 implementation whose IFormatProvider.GetFormat method returns a NumberFormatInfo object. Typically, provider is a NumberFormatInfo or CultureInfo object. The provider parameter supplies culture-specific information used in formatting. If provider is null, the thread current culture is used.

The following example displays a Decimal value using each of the supported standard numeric format specifiers for several different cultures.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft