I’m not sure I understand what exactly do you want to do, or why would
you want to do that.
From: http://en.wikipedia.org/wiki/Rounding :
Round half to even
A tie-breaking rule that is less biased is round half to even, namely:
If the fraction of y is 0.5, then q is the even integer nearest to y.
Thus, for example, +23.5 becomes +24, as does +24.5; while −23.5 becomes
−24, as does −24.5.
This method treats positive and negative values symmetrically, and is
therefore free of sign bias. More importantly, for reasonable
distributions of y values, the expected (average) value of the rounded
numbers is the same as that of the original numbers. However, this rule
will introduce a towards-zero bias for even numbers, and a
towards-infinity bias for odd ones.
The point is that I want unbiased rounding of values that are resulting
from physical measurements; when you can read a measure to 1 decimal,
say 105.5, 104.7, 105.1, 104.9, 104.5, et cetera, and you round these
values to 0 decimals the standard ruby way, then all values ending in .5
will be rounded up; this causes a bias in the average, since actually
chances are equal that 104.5 is either 104 or 105. One way to prevent
this bias is by rounding to the nearest even digit.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.