Round2BR is combination of the function Round and Round2, and returns aValue rounded to the number of decimal places specified by aDigit.  

The rounding uses banker’s rules where an exact half value of .5 causes rounding up to the next even integer value, so 1.5 would round up to 2 and 6.5 would round down to 6.   

  • 0.5 rounds down to 0.

  • 1.5 rounds up to 2.

  • 86.5 rounds down to 86.

  • 34.5 rounds down to 34.

Other decimal fractions round as you would expect -

  • 2.4 would round down to 2.

  • 0.4 would round down to 0.

  • 0.6 would round up to 1.

  • 4.8 would round up to 5.

  • 5.3 would round down to 5.

Declaration: Function Round2BR(aValue : Extended; aDigit : integer) : Extended

Examples as below.

Procedure OnMapEvent(var Value:variant);
begin
Value := Round2BR(3.4,2); // result is 3.4
Value := Round2BR(3.5,2); // result is 3.5
Value := Round2BR(123.454,2); // result is 123.45
Value := Round2BR(123.455,2); // result is 123.46
Value := Round2BR(123.456,2); // result is 123.46
Value := Round2BR(745.4546,3); // result is 745.455
Value := Round2BR(745.4545,3); // result is 745.454
Value := Round2BR(80.374,2); // result is 80.37
Value := Round2BR(80.375,2); // result is 80.38
Value := Round2BR(80.265,2); // result is 80.26
LogInfo(FloatToStr(Round2BR(0.4,0)));         // result is 0
  LogInfo(FloatToStr(Round2BR(0.5,0)));         // result is 0
  LogInfo(FloatToStr(Round2BR(0.6,0)));         // result is 1
  LogInfo(FloatToStr(Round2BR(1.5,0)));         // result is 2
  LogInfo(FloatToStr(Round2BR(2.4,0)));         // result is 2
  LogInfo(FloatToStr(Round2BR(4.8,0)));         // result is 5
  LogInfo(FloatToStr(Round2BR(5.3,0)));         // result is 5
  LogInfo(FloatToStr(Round2BR(86.5,0)));        // result is 86
  LogInfo(FloatToStr(Round2BR(34.5,0)));        // result is 34
end;