I want to be rounded off this way
13.1, round to 13.5
13.2, round to 13.5
13.3, round to 13.5
13.4, round to 13.5
13.5 = 13.5
13.6, round to 14.0
13.7, round to 14.0
13.8, round to 14.0
13.9, round to 14.0
sorry for modification i need in the above way... did this way but not appropriate
doubleValue = Math.Round((doubleValue * 2), MidpointRounding.ToEven) / 2;
d is a double.
If it is required for
13.1, round to 13.5
and13.9, round to 14.0
, then:Nearest
0.5
for13.6
and13.7
is13.5
, so you have correct solution.for yours table of values:
works well for you solution heres the complete console program
you simply would need to change
0.5
to some other number if the rounding requirement changes in futureI don't know if it is proper way, but it works. Try this if you want:
This works, I just tested it;