Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

While you may remember the simple rounding rules you learning in school as a kid - there are in fact more complex rounding rules that are used in real life to overcome bias and errors in various scenarios.

Table of Contents
minLevel1
maxLevel2
outlinefalse
typelist
printablefalse

Be Consistent

We want to use the same rounding function consistently so that we can avoid having conflicting values on account of rounding methods.

Method to Use: Math.Round(…)

...

Round to nearest, ties to even – rounds to the nearest value; if the number falls midway, it is rounded to the nearest value with an even least significant digit.

A tie-breaking rule without positive/negative bias and without bias toward/away from zero is round half to even. By this convention, if the fractional part of x is 0.5, then y is the even integer nearest to x. Thus, for example, +23.5 becomes +24, as does +24.5; however, −23.5 becomes −24, as does −24.5. This function minimizes the expected error when summing over rounded figures, even when the inputs are mostly positive or mostly negative, provided they are neither mostly even nor mostly odd.

This variant of the round-to-nearest method is also called convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, odd–even rounding, or bankers' rounding.

(from Wikipedia)

Be Consistent

We want to use the same rounding function consistently so that we can avoid having conflicting values on account of rounding methods.

Methods to Avoid

We want to avoid using the string formatting functions because they use a different rounding function.

...