How to cast (convert) double or single to int in VB.NET

4 Answers

0 votes
Imports System

Public Class Test
    Public Shared Sub Main()
        Console.WriteLine(Int(29.9))
        Console.WriteLine(Fix(29.9))
        
        Console.WriteLine(Int(-29.9))
        Console.WriteLine(Fix(-29.9))
        
        Console.WriteLine(Int(29.2))
        Console.WriteLine(Fix(29.2))
        
        Console.WriteLine(Int(-29.2))
        Console.WriteLine(Fix(-29.2))
    End Sub
End Class



' run:
' 
' 29
' 29
' -30
' -29
' 29
' 29
' -30
' -29

 



answered Apr 20, 2019 by avibootz
0 votes
Imports System

Public Class Test
    Public Shared Sub Main()
        Console.WriteLine(CInt(29.9))
        Console.WriteLine(CInt(-29.9))
        Console.WriteLine(CInt(29.2))
        Console.WriteLine(CInt(-29.2))
    End Sub
End Class



' run:
' 
' 30
' -30
' 29
' -29

 



answered Apr 20, 2019 by avibootz
0 votes
Public Class Test
    Public Shared Sub Main()
        Console.WriteLine(CInt(Int(29.9)))
        Console.WriteLine(CInt(Fix(29.9)))
        
        Console.WriteLine(CInt(Int(-29.9)))
        Console.WriteLine(CInt(Fix(-29.9)))
        
        Console.WriteLine(CInt(Int(29.2)))
        Console.WriteLine(CInt(Fix(29.2)))
        
        Console.WriteLine(CInt(Int(-29.2)))
        Console.WriteLine(CInt(Fix(-29.2)))
    End Sub
End Class



' run:
' 
' 29
' 29
' -30
' -29
' 29
' 29
' -30
' -29

 



answered Apr 20, 2019 by avibootz
0 votes
Imports System

Public Class Test
    Public Shared Sub Main()
        Console.WriteLine(CInt(Int(385.7638)))
        Console.WriteLine(CInt(Fix(385.7638)))
        
        Console.WriteLine(CInt(Int(-385.7638)))
        Console.WriteLine(CInt(Fix(-385.7638)))
        
        Console.WriteLine(Int(385.7638))
        Console.WriteLine(Fix(385.7638))
        
        Console.WriteLine(Int(-385.7638))
        Console.WriteLine(Fix(-385.7638))
    End Sub
End Class



' run:
' 
' 385
' 385
' -386
' -385
' 385
' 385
' -386
' -385

 



answered Apr 20, 2019 by avibootz

Related questions

1 answer 165 views
165 views asked Nov 15, 2021 by avibootz
1 answer 162 views
1 answer 129 views
2 answers 201 views
201 views asked Dec 2, 2020 by avibootz
1 answer 165 views
2 answers 221 views
...