本頁是否能提供幫助?
您對此內容的意見反應十分重要。 請告訴我們您的想法。
其他意見反應?
剩餘 1500 個字元
MSDN Library
EN
本內容沒有您的語言版本,但有英文版本。

Convert.ToString Method (Single)

Converts the value of the specified single-precision floating point number to its equivalent String representation.

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

public static string ToString(
	float value
)

Parameters

value
Type: System.Single
A single-precision floating point number.

Return Value

Type: System.String
The String equivalent of the value of value.

This implementation is identical to Single.ToString.

The following code sample illustrates the conversion of a Single to a String, using ToString.


public void ConvertStringFloat(string stringVal)
{
   float floatVal = 0;

   try
   {
      floatVal = System.Convert.ToSingle(stringVal);
      outputBlock.Text += String.Format(
         "The string as a float is {0}.", floatVal) + "\n";
   }
   catch (System.OverflowException)
   {
      outputBlock.Text += String.Format(
         "The conversion from string-to-float overflowed.") + "\n";
   }
   catch (System.FormatException)
   {
      outputBlock.Text += String.Format(
         "The string is not formatted as a float.") + "\n";
   }
   catch (System.ArgumentNullException)
   {
      outputBlock.Text += String.Format(
         "The string is null.") + "\n";
   }

   // Float to string conversion will not overflow.
   stringVal = System.Convert.ToString(floatVal);
   outputBlock.Text += String.Format(
      "The float as a string is {0}.", stringVal) + "\n";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

顯示:
© 2015 Microsoft