How to convert a specified value to a 64-bit signed integer (Convert.ToInt64) in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim arr As Single() = {Single.MinValue, -2.18e10F, -4012.309F, -18.07F, 
			                   0F, 7.018e-16F, 981.276F, 23004.7815F, Single.MaxValue}

        For Each value As Single In arr
            Try
                Dim result As Long = Convert.ToInt64(value)
                Console.WriteLine("{0} = {1}", value, result)
            Catch __unusedOverflowException1__ As OverflowException
                Console.WriteLine("{0} is outside the range of the Int64 type", value)
            End Try
        Next
    End Sub
End Class



' run:
'
' -3.402823E+38 is outside the range of the Int64 type
' -2.18E+10 = -21799999488
' -4012.309 = -4012
' -18.07 = -18
' 0 = 0
' 7.018E-16 = 0
' 981.276 = 981
' 23004.78 = 23005
' 3.402823E+38 is outside the range of the Int64 type
' 

 



answered May 24, 2024 by avibootz
...