Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SingleConverter Class

Provides a type converter to convert single-precision, floating point number objects to and from various other representations.

For a list of all members of this type, see SingleConverter Members.

System.Object
   System.ComponentModel.TypeConverter
      System.ComponentModel.BaseNumberConverter
         System.ComponentModel.SingleConverter

[Visual Basic]
Public Class SingleConverter
   Inherits BaseNumberConverter
[C#]
public class SingleConverter : BaseNumberConverter
[C++]
public __gc class SingleConverter : public BaseNumberConverter
[JScript]
public class SingleConverter extends BaseNumberConverter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This converter can only convert a single-precision, floating point number object to and from a string. The Single value type represents a single-precision 32-bit number with values ranging from negative 3.402823e38 to positive 3.402823e38.

Note   You should never create an instance of SingleConverter. Instead, call the GetConverter method of TypeDescriptor. For more information, see the examples in the TypeConverter base class and Implementing a Type Converter.

Example

[Visual Basic, C#, C++] The following sample converts a variable of type Single to a string, and vice versa.

[Visual Basic] 
Dim s As [Single] = 3.402823E+10F
Dim mySStr As String = "3.402823E+10"
Console.WriteLine(TypeDescriptor.GetConverter(s).ConvertTo(s, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(s).ConvertFrom(mySStr))

[C#] 
Single s=3.402823E+10F;
string mySStr="3.402823E+10";
Console.WriteLine(TypeDescriptor.GetConverter(s).ConvertTo(s, typeof(string))); 
Console.WriteLine(TypeDescriptor.GetConverter(s).ConvertFrom(mySStr));    

[C++] 
Single s( 3.402823E+10F );
String* mySStr = S"3.402823E+10";
Console::WriteLine(TypeDescriptor::GetConverter(__box(s))->ConvertTo(__box(s), __typeof(String)));
Console::WriteLine(TypeDescriptor::GetConverter(__box(s))->ConvertFrom(mySStr));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

SingleConverter Members | System.ComponentModel Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.