My last goal is always to round to the nearest even integer.
For example, the number 1122.5196
I want as result 1122
. I have tried this options:
Math.Round(1122.5196d, 0, MidpointRounding.ToEven); // result 1123Math.Round(1122.5196d, 0, MidpointRounding.AwayFromZero); // result 1123
At the end, what I would like to get it is always the nearest even integer. For example:
1122.51 --> 1122
1122.9 --> 1122
(because the nearest int is1123
but it is odd, and1122
is nearer than1124
)1123.0 --> 1124
(the next even value, the next higher even value)
I only work with positive numbers.
And so on.
There are some method that do that or I should to implement my own method?