How to round a number to a multiple of 5 in VB.NET

1 Answer

0 votes
Imports System
 
Public Class Program
    Public Shared Function roundToMultipleOf(ByVal number As Double, ByVal multipleOf As Double) As Double
        Return multipleOf * CLng(Math.Round(number / multipleOf, MidpointRounding.AwayFromZero))
    End Function
 
    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine(roundToMultipleOf(9, 5))
        Console.WriteLine(roundToMultipleOf(19, 5))
        Console.WriteLine(roundToMultipleOf(71, 5))
    End Sub
End Class
 
 
   
   
' run:
'
' 10
' 20
' 70
'

 



answered Jun 10, 2024 by avibootz
...