Difference between revisions of "Round/de"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "Rundet eine Fliesskommazahl auf eine Ganzzahl. =Round= ==Deklaration:== <syntaxhighlight>function Round(X: Real): Longint;</syntaxhighlight> ==Beispiel:== ===Code:=== <synta...")
 
Line 13: Line 13:
 
   WriteLn( Round(8.7) );
 
   WriteLn( Round(8.7) );
 
   WriteLn( Round(8.3) );
 
   WriteLn( Round(8.3) );
   // examples of "bankers rounding" - .5 is adjusted to the nearest even number
+
   // Beispiele für "Banker-Runden" - .5 wird auf die nächste gerade Zahl eingestellt
 
   WriteLn( Round(2.5) );
 
   WriteLn( Round(2.5) );
 
   WriteLn( Round(3.5) );
 
   WriteLn( Round(3.5) );

Revision as of 21:10, 22 March 2018

Rundet eine Fliesskommazahl auf eine Ganzzahl.

Round

Deklaration:

function Round(X: Real): Longint;

Beispiel:

Code:

var
  i1, i2: Integer;
begin
  WriteLn( Round(8.7) );
  WriteLn( Round(8.3) );
  // Beispiele für "Banker-Runden" - .5 wird auf die nächste gerade Zahl eingestellt
  WriteLn( Round(2.5) );
  WriteLn( Round(3.5) );

  i := Round(12.50); // Rundet ab
  WriteLn(i);
  i := Round(12.51); // Rundet auf
  WriteLn(i);
end.

Ausgabe:

9
8
2
4
12
13

See also: