DecimalConverter
Class
Definition
Provides a type converter to convert Decimal objects to and from various other representations.
public class DecimalConverter : System.ComponentModel.BaseNumberConverter
- Inheritance
Inherited Members
System.ComponentModel.BaseNumberConverter
System.ComponentModel.TypeConverter
System.Object
Examples
The following code example converts a variable of type Decimal to a string, and vice versa.
Decimal myDec(40);
String^ myDStr = "20";
Console::WriteLine( TypeDescriptor::GetConverter( myDec )->ConvertTo( myDec, String::typeid ) );
Console::WriteLine( TypeDescriptor::GetConverter( myDec )->ConvertFrom( myDStr ) );
decimal myDec = 40;
string myDStr = "20";
Console.WriteLine(TypeDescriptor.GetConverter(myDec).ConvertTo(myDec, typeof(string)));
Console.WriteLine(TypeDescriptor.GetConverter(myDec).ConvertFrom(myDStr));
Dim myDec As Decimal = 40
Dim myDStr As String = "20"
Console.WriteLine(TypeDescriptor.GetConverter(myDec).ConvertTo(myDec, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(myDec).ConvertFrom(myDStr))
Remarks
This converter can only convert a decimal object to and from a string.
Note
You should never create an instance of the DecimalConverter class. Instead, call the GetConverter method of the TypeDescriptor class. For more information, see the examples in the TypeConverter base class.
For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.
Constructors
| DecimalConverter() |
Initializes a new instance of the DecimalConverter class. |
Methods
| CanConvertTo(ITypeDescriptorContext, Type) |
Gets a value indicating whether this converter can convert an object to the given destination type using the context. |
| ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type) |
Converts the given value object to a Decimal using the arguments. |