Description |
The Round function rounds a floating point Number to an Integer value.
The rounding uses Bankers rules, where an exact half value causes a rounding to an even number:
12.4 rounds to | 12 |
12.5 rounds to | 12 // Round down to even |
12.6 rounds to | 13 |
| |
13.4 rounds to | 13 |
13.5 rounds to | 14 // Round up to even |
13.6 rounds to | 14 |
|
|
Notes |
The Trunc function does the same, but returns the integer in an Integer value.
|
|
Related commands |
Frac |
|
The fractional part of a floating point number |
Int |
|
The integer part of a floating point number as a float |
Trunc |
|
The integer part of a floating point number |
|
|
|
Example code : A simple example |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses // The System unit does not need to be defined SysUtils, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); begin
ShowMessage('Round(12.75) = '+IntToStr(Round(12.75)));
ShowMessage('Trunc(12.75) = '+IntToStr(Trunc(12.75)));
ShowMessage(' Int(12.75) = '+FloatToStr(Int(12.75)));
ShowMessage(' Frac(12.75) = '+FloatToStr(Frac(12.75)));
end; end.
|
Hide full unit code |
Round(12.75) = 13
Trunc(12.75) = 12
Int(12.75) = 12
Frac(12.75) = 0.75
|
|