c# - Math.Round returning a rounded up for odd values but rounds down for even -


i trying found float using math round found following

0.5 --> 0 1.5 --> 2 2.5 --> 2 3.5 --> 4 

and on. believe due floating point error, not quite sure how. how can around numbers round properly?

from documentation;

the integer nearest a. if fractional component of halfway between 2 integers, 1 of , other odd, number returned. note method returns double instead of integral type.

math.round method has overloads takes midpointrounding parameter can specify rounding value if midway between 2 numbers.

awayfromzero  

when number halfway between 2 others, rounded toward nearest number away zero.

toeven 

when number halfway between 2 others, rounded toward nearest number.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -