Round

From Delphi Pascal wiki
Jump to navigation Jump to search

Rounds a Real-type value to an Integer-type value.

Declaration
function Round(X: Real): Longint;
Target
Windows, Real, Protected
Remarks
X is a real-type expression. Round returns a Longint value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is the number with the greatest absolute magnitude. A run-time error occurs if the rounded value of X is not within the Longint range.
See Also
Int
Trunc


Sample Code

{Round.PAS}
{Sample code for the Round function.}

{ For Windows: }
{ uses WinCrt; }

begin
  Writeln(1.4, ' rounds to ', Round(1.4));
  Writeln(1.5, ' rounds to ', Round(1.5));
  Writeln(-1.4, ' rounds to ', Round(-1.4));
  Writeln(-1.5, ' rounds to ', Round(-1.5));
end.