How to round a floating-point number to an integer in VB.NET

1 Answer

0 votes
Imports System

Class Program
	Public Shared Sub Main()
        Dim x As Single = 9382.4F
        Dim y As Long = CLng(Math.Round(x))
        Console.WriteLine(y)
		
        x = 9382.5F
        y = CLng(Math.Round(x))
        Console.WriteLine(y)
		
        x = 9382.6F
        y = CLng(Math.Round(x))
        Console.WriteLine(y)
    End Sub
End Class



' run:
'
' 9382
' 9382
' 9383
'

 



answered May 14, 2025 by avibootz

Related questions

1 answer 76 views
1 answer 71 views
1 answer 56 views
4 answers 212 views
3 answers 225 views
2 answers 134 views
...