The answers obtained by using the Round function in Delphi are sometimes different from what we expected:
Rounding is used to leave even numbers. That is, when the rounding or rounding digit is greater than or less than five, it is processed by rounding. When the rounding or rounding digit is equal to five, it depends on what the previous digit is. According to whether odd or even is entered, it always returns an even value.
Example results
i:= Round(11.5) 12
i:= Round(10.5) 10
This kind of Round is actually based on the banker's algorithm, which is generally used in statistics, and is more scientific than the traditional "rounding".
If you want to use the traditional "rounding" method, you can use the following function:
function RoundClassic(R: Real): Int64;
begin
Result:= Trunc(R);
if Frac(R) >= 0.5 then
Result:= Result + 1;
end;
In fact, this problem exists in VB, Excel, and .net related languages.