Share via

Nearest or Round Function

Singos 20 Reputation points
2023-07-17T12:41:29.4+00:00

Original Value: 21000, Rounded Value: 20000

Original Value: 21500, Rounded Value: 20000

Original Value: 22000, Rounded Value: 20000

Original Value: 22400, Rounded Value: 20000

Original Value: 22500, Rounded Value: 25000

Original Value: 22800, Rounded Value: 25000

Original Value: 23000, Rounded Value: 25000

Original Value: 14000, Rounded Value: 15000

Original Value: 35000, Rounded Value: 35000

Original Value: 25000, Rounded Value: 25000

i need your help in vb.net windows forms

i need to round till the nearest 5000 as my example for any given value

Developer technologies | Windows Forms
0 comments No comments

Answer accepted by question author

Olaf Helper 47,621 Reputation points
2023-07-17T13:03:39.0233333+00:00

But that's only simple math: Divide by 5,000, round, multiply by 5,000

Module Module1

    Sub Main()
        Console.WriteLine(Round5000(21000))
        Console.WriteLine(Round5000(22800))
        Console.ReadKey()
    End Sub

    Public Function Round5000(ByVal number As Integer) As Integer
        Dim result As Double
        result = Math.Round(number / 5000.0, 0) * 5000
        Return Convert.ToInt64(result)
    End Function
End Module

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.