Round
Deutsch · English · Esperanto · Suomi · Русский
The RTL System unit contains function Round, which rounds a Real-type value to an Integer-type value. It's input parameter is a real-type expression and Round returns a Int64 value that is the value of the input rounded to the nearest whole number. If the input value is exactly halfway between two whole numbers - N.5 - then "bankers rounding" is used, with the result being the nearest even number.
Declaration
function Round(X: Real): int64;Example Usage
begin
WriteLn( Round(8.7) );
WriteLn( Round(8.3) );
// examples of "bankers rounding" - .5 is adjusted to the nearest even number
WriteLn( Round(2.5) );
WriteLn( Round(3.5) );
end.Output
9
8
2
4See also
system.roundmath.ceil- round upmath.floor- round down- frac - returns the fractional part of a floating point value
- trunc - round towards zero
- int - returns the integer part of a floating point value
- div - integer division
- Comparison of approaches for rounding to an integer
From the Free Pascal wiki, page "Round", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.