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

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -