다음을 통해 공유


Single.ToString Method (String)

Converts the value of the current Single object to its equivalent string representation, using a specified format.

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

Syntax

public string ToString (
         stringformat
)

Parameters

  • format
    A string that takes the form Axx, where A is an alphabetic character called the format specifier, and xx is an optional integer called the precision specifier. The precision specifier ranges from 0 to 99 and affects the number of digits in the result.

    If format is a null reference or an empty string, the general format specifier, 'G', is used.

    The following table describes the standard Single format specifiers.

    Format specifier Name Description
    F or f Fixed Point

    The number is converted to a string of the form "ddd.ddd…" where each 'd' indicates a digit (0-9), prefixed by a minus sign if the number is negative.

    The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision is 2.

    G or g General

    The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. The precision specifier is ignored.

    N or n Number The number is converted to a string of the form "-d,ddd,ddd.ddd…", where '-' indicates a negative symbol if required, 'd' indicates a digit (0-9), ',' indicates a thousand separator between number groups, and '.' indicates a decimal point symbol. The actual number group size and thousand separator are specified by the current NumberFormatInfo object. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision is 2.

Return Value

A string representation of the value of the current Single object, in the specified format.

Version Information

Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, and 4.1.

See Also

Reference

Single Structure
Single Members
System Namespace