Cases:
Var
I, J:integer;
Begin
I: = Round (1.5); I equals 2
J: = Round (2.5); J equals 2.
End
The answers used in Delphi with the round function are sometimes not the same as we expected: The four-house six into the five-left double. That is, when the rounding or entering bit is greater than or less than five, it is processed by rounding.
, and when the house or into a bit equal to five o'clock, it is necessary to see what the previous one, according to Chi Jin even, it always returns an even value.
Cases:
i:= Round (11.5)//i equals 12
i:= Round (10.5)//i equals 10
This kind of round is actually according to banker algorithm, statistically generally use this algorithm, than the traditional "rounding" to science.
If you want to use the traditional "rounding" method, you can use the following function:
function Roundclassic (r:real)
2.trunc(Get integer portion of x)
such as:trunc( -123.55) =-123, Floor (123.55) =123
3.Ceil(Gets the smallest integer greater than or equal to X)
such as: Ceil ( -123.55) =-123, Ceil (123.15) =124
4.Floor (gets the largest integer less than or equal to X)
such as: Floor ( -123.55) =-124,floor (123.55) =123
Note: Floor and ceil are functions in the math unit, uses math before use
Delphi's rounding function round, trunc, ceil, and floor