Bagikan melalui


Single.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 can be PositiveInfinitySymbol, NegativeInfinitySymbol, NaNSymbol, or a string of the form:

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

Optional elements are framed in square brackets ([ and ]). Elements containing the term "digits" consist of a series of numeric characters ranging from 0 to 9. The following table lists each element.

Element

Description

sign

A negative sign or positive sign symbol.

integral-digits

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.

fractional-digits

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

'e'

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

exponential-digits

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".

NoteNote:

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

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 GetFormat method returns a NumberFormatInfo object. Typically, provider is a CultureInfo object or a NumberFormatInfo object. The provider parameter supplies culture-specific information used in formatting. If provider is nulla null reference (Nothing in Visual Basic), the return value is formatted using the NumberFormatInfo data for the current culture.

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

Examples

The following example displays the string representation of two Single values using CultureInfo objects that represent several different cultures.

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.