Convert.ToSingle (Object) converts object to a single-precision floating-point number. : Convert to Single « Development « VB.Net






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

1.Convert.ToSingle (Boolean) converts Boolean value to single-precision floating-point number.
2.Convert.ToSingle (Byte) converts 8-bit unsigned integer to single-precision floating-point number.
3.Convert.ToSingle (Decimal) converts decimal number to single-precision floating-point number.
4.Convert.ToSingle (Double) converts double number to single-precision floating-point number.
5.Convert.ToSingle (Int16) converts 16-bit signed integer to floating-point number.
6.Convert.ToSingle (Int32) converts 32-bit signed integer to single-precision floating-point number.
7.Convert.ToSingle (Int64) converts 64-bit signed integer to single-precision floating-point number.
8.Convert.ToSingle (SByte) converts signed integer to single-precision floating-point number.
9.Convert.ToSingle (String) converts string to single-precision floating-point number.
10.Convert.ToSingle (UInt16) converts 16-bit unsigned integer to single-precision floating-point number.
11.Convert.ToSingle (UInt32) converts 32-bit unsigned integer to single-precision floating-point number.
12.Convert.ToSingle (UInt64) converts 64-bit unsigned integer to single-precision floating-point number.