Mono Class Library: System.Single Overview | Members

System.Single.ToString Method

Returns a string representation of the value of the current instance.

public string ToString (string format)

Parameters

format
A string that specifies the format of the returned string.
Note: For a list of valid values, see float.ToString (string, IFormatProvider ).

Returns

A string representation of the current instance formatted as specified by format . The string takes into account the current system culture.

Exceptions

TypeReason
FormatExceptionformat is invalid.

Remarks

This version of float.ToString is equivalent to float.ToString (format, null ).

If format is a null reference, the general format specifier "G" is used.

Example

The following example shows the effects of various formats on the string returned by float.ToString .

C# Example

using System;
class test {
 public static void Main() {
   float f = 1234.567f;
   Console.WriteLine(f);
   string[] fmts = {"C","E","e5","F","G","N","P","R"};
   for (int i=0;i<fmts.Length;i++)
     Console.WriteLine("{0}: {1}", 
       fmts[i],f.ToString(fmts[i]));
 }
}
   

The output is

1234.567
C: $1,234.57
E: 1.234567E+003
e5: 1.23457e+003
F: 1234.57
G: 1234.567
N: 1,234.57
P: 123,456.70 %
R: 1234.567

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0