Rounding 0.5 to 1

Hello,

Im having issues with rounding numbers. I want the following conversions:
0 → 0
0.1 → 0
0.2-> 0
0.3 → 0
0.4 → 0
0.5 → 1
0.6 → 1
0.7 → 1
0.8 → 1
0.9 → 1
1 → 1

I am using the following code
“Math.Round(“double value”, 2, MidpointRounding.AwayFromZero)”

this code converts 0.5 → 0 ( I want 0.5 → 1)

Thanks for the help :slight_smile:

edit:

I fixed this issue by adding 0.1 to the number before rounding it.

in case of resulting string is ok:
grafik

Quick, Dirty
grafik

And also:
grafik

add 0.1 the number before rounding

Hi,
another solution:

If dbl_num < 0.5 Then
    Math.Floor(Math.Round(dbl_num,2,MidpointRounding.AwayFromZero))
Else
    Math.Ceiling(Math.Round(dbl_num,2,MidpointRounding.AwayFromZero))

That is a terrible solution. The various rounding functions etc work just fine.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.