Convert.ToSingle (Object) converts object to a single-precision floating-point number.
Class Sample
Public Shared Sub Main()
Dim values() As Object = { True, "a"c, 123, 1.999e32, "9.99", "1e-02", _
Decimal.MaxValue }
Dim result As Single
For Each value As Object In values
Try
result = Convert.ToSingle(value)
Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", _
value.GetType().Name, value, _
result.GetType().Name, result)
Catch e As FormatException
Console.WriteLine("FormatException",value.GetType().Name, value)
Catch e As OverflowException
Console.WriteLine("OverflowException",value.GetType().Name, value)
Catch e As InvalidCastException
Console.WriteLine("InvalidCastException",value.GetType().Name, value)
End Try
Next
End Sub
End Class
Related examples in the same category