The Round function rounds a floating-point number, returning the value specified by aValue rounded to the nearest integer (or whole number) using unbiased rounding (also known as banker’s rounding).    

Bankers rounding is a rounding algorithm, where numbers of a value that is equidistant from the two nearest integers are rounded to the nearest even integer.   An even integer being 0, 2, 4, 6, 8 etc., as opposed to an odd integer being 1, 3, 5, 7 etc.    This method is also known as statistician’s rounding, or convergent rounding.

The rounding uses banker’s rules where an exact half value of .5 causes rounding up to the next even integer value, as follows -

  • 1.5 rounds up to 2.

  • 6.5 rounds down to 6.   

  • 0.5 rounds down to 0.

  • 1.5 rounds up to 2.

  • 2.5 rounds down to 2.

  • 3.5 rounds up to 4.

  • 86.5 rounds down to 86.

  • 34.5 rounds down to 34.

Other decimal fractions round as you would expect -

  • 2.4 rounds down to 2.

  • 0.4 rounds down to 0.

  • 0.6 rounds up to 1.

  • 4.8 rounds up to 5.

  • 5.3 rounds down to 5.

The theoretical advantage of using bankers rounding is that it is unbiased, and produces a more even and better result, where the average of all errors is as close to 0.0 as can be achieved.

A whole number such as 5.0 or 36.0 would not round to anything other than itself.

Also refer to Round2, Round2Up, or Round2BR for functions that round to a specified number of decimal places. Round2Up would be the usual rounding function that would be used.

Declaration: Function Round(aValue : Extended) : Integer

Several examples follow as below.

Procedure OnMapEvent(var Value:variant);
begin
Value:= Round(123.455); // result is 123
Value:= Round(65.51); // result is 66
Value:= Round(8622.143); // result is 8622
Value:= Round(7.74); // result is 8
Value:= Round(4.8); // result is 5
Value:= Round(86.5); // result is 86
Value:= Round(2.4); // result is 2
Value:= Round(0.5); // result is 0
end;