Поделиться через


Decimal.ToString Method (IFormatProvider)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Function ToString ( _
    provider As IFormatProvider _
) As String
[SecuritySafeCriticalAttribute]
public string ToString(
    IFormatProvider provider
)

Parameters

Return Value

Type: System.String
The string representation of the value of this instance as specified by provider.

Implements

IConvertible.ToString(IFormatProvider)

Remarks

The return value 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:

NoteNote:

Because the Decimal data type is not supported on the Macintosh OS X operating system, the string representation of a Decimal value may be different from those of the other .NET Framework numeric types that are supported by OS X.

The provider parameter is an IFormatProvider implementation whose IFormatProvider.GetFormat method returns a NumberFormatInfo object. Typically, provider is a NumberFormatInfo object or a CultureInfo object. The provider parameter supplies culture-specific information used in formatting. If provider is nulla null reference (Nothing in Visual Basic), the thread current culture is used.

To convert a Decimal value to its string representation using a specified culture and a specific format string, call the Decimal.ToString(String, IFormatProvider) method.

Examples

The following example displays the string representation of a Decimal value using CultureInfo objects that represent several different cultures.

Dim value As Decimal = -16325.62D
' Display value using the invariant culture.
outputBlock.Text &= value.ToString(CultureInfo.InvariantCulture) & vbCrLf
' Display value using the en-GB culture.
outputBlock.Text &= value.ToString(New CultureInfo("en-GB")) & vbCrLf
' Display value using the de-DE culture.
outputBlock.Text &= value.ToString(New CultureInfo("de-DE")) & vbCrLf
' This example displays the following output:
'       -16325.62
'       -16325.62
'       -16325,62
decimal value = -16325.62m;
// Display value using the invariant culture.
outputBlock.Text += value.ToString(CultureInfo.InvariantCulture) + "\n";
// Display value using the en-GB culture.
outputBlock.Text += value.ToString(new CultureInfo("en-GB")) + "\n";
// Display value using the de-DE culture.
outputBlock.Text += value.ToString(new CultureInfo("de-DE")) + "\n";
// This example displays the following output:
//       -16325.62
//       -16325.62
//       -16325,62

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.