Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToDecimal (Object) converts object to decimal number

Class Sample    Public Shared Sub Main()         Dim values() As Object = { False, "a"c, 112323, "2342342349.78", "1e-02", _                                    1.6222227e03, "A100", "1,033.67", Double.MaxValue }            Dim result As Decimal                  For Each value As Object In values            Try               result = Convert.ToDecimal(value)               Console.WriteLine("Converted the {0} value {1} to {2}.", _                                 value.GetType().Name, value, result)            Catch e As OverflowException               Console.WriteLine("OverflowException")            Catch e As FormatException               Console.WriteLine("FormatException")            Catch e As InvalidCastException               Console.WriteLine("InvalidCastException")            End Try                              Next    End Sub 'Main End Class 'Sample