Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToSingle (String) converts string to single-precision floating-point number

Class Sample    Public Shared Sub Main()         Dim values() As String = { "-1,999.99999", "1AFF", "1e-35","999.99999", "1.99e999"}         Dim result As Single                  For Each value As String 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("Unable to convert '{0}' to a Single.", value)                        Catch e As OverflowException               Console.WriteLine("'{0}' is outside the range of a Single.", value)            End Try         Next            End Sub  End Class