指定した 8 ビット符号なし整数値を等価の単精度浮動小数点数に変換します。
Overloads Public Shared Function ToSingle( _
ByVal value As Byte _) As Single
[C#]
public static float ToSingle(bytevalue);
[C++]
public: static float ToSingle(unsigned charvalue);
[JScript]
public static function ToSingle(
value : Byte) : float;
パラメータ
- value
8 ビット符号なし整数。
戻り値
value の値と等価な単精度浮動小数点数。
解説
ToSingle を使用して、 Byte を Single に変換する方法については、次のコード例を参照してください。
Public Sub ConvertByteSingle(ByVal byteVal As Byte)
Dim singleVal As Single
' Byte to float conversion will not overflow.
singleVal = System.Convert.ToSingle(byteVal)
System.Console.WriteLine("The byte as a single is {0}.", _
singleVal)
' Single to byte conversion can overflow.
Try
byteVal = System.Convert.ToByte(singleVal)
System.Console.WriteLine("The single as a byte is {0}.", _
byteVal)
Catch exception As System.OverflowException
System.Console.WriteLine( _
"Overflow in single-to-byte conversion.")
End Try
End Sub
[C#]
public void ConvertByteSingle(byte byteVal) {
float floatVal;
// Byte to float conversion will not overflow.
floatVal = System.Convert.ToSingle(byteVal);
System.Console.WriteLine("The byte as a float is {0}.",
floatVal);
// Float to byte conversion can overflow.
try {
byteVal = System.Convert.ToByte(floatVal);
System.Console.WriteLine("The float as a byte is {0}.",
byteVal);
}
catch (System.OverflowException) {
System.Console.WriteLine(
"The float value is too large for a byte.");
}
}
[C++]
void ConvertByteSingle(Byte byteVal)
{
float floatVal;
// Byte to float conversion will not overflow.
floatVal = System::Convert::ToSingle(byteVal);
System::Console::WriteLine(S"The Byte as a float is {0}.",
__box(floatVal));
// Float to Byte conversion can overflow.
try {
byteVal = System::Convert::ToByte(floatVal);
System::Console::WriteLine(S"The float as a Byte is {0}.",
__box(byteVal));
} catch (System::OverflowException*) {
System::Console::WriteLine(S"The float value is too large for a Byte.");
}
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
Convert クラス | Convert メンバ | System 名前空間 | Convert.ToSingle オーバーロードの一覧