Difference between revisions of "Round"
From Lazarus wiki
Jump to navigationJump to search(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Round}} | {{Round}} | ||
− | The [[RTL]] [[System unit]] contains function '''Round''', which rounds a [[Real]]-type value to an [[Integer]]-type value. | + | The [[RTL]] [[System unit]] contains [[Function|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 [[ | + | 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 == | |
− | |||
− | <syntaxhighlight> | + | <syntaxhighlight lang="pascal"> |
+ | function Round(X: Real): int64; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Example Usage == | ||
+ | |||
+ | <syntaxhighlight lang="pascal"> | ||
begin | begin | ||
WriteLn( Round(8.7) ); | WriteLn( Round(8.7) ); | ||
Line 17: | Line 22: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | === Output === | |
− | 9 | + | |
− | 8 | + | 9 |
− | 2 | + | 8 |
− | 4 | + | 2 |
+ | 4 | ||
+ | |||
+ | == See also == | ||
− | |||
− | |||
− | |||
− | |||
− | [[ | + | * {{Doc|package=RTL|unit=system|identifier=round|text=<syntaxhighlight lang="pascal" inline>system.round</syntaxhighlight>}} |
+ | * {{Doc|package=RTL|unit=math|identifier=ceil|text=<syntaxhighlight lang="pascal" inline>math.ceil</syntaxhighlight>}} - round up | ||
+ | * {{Doc|package=RTL|unit=math|identifier=floor|text=<syntaxhighlight lang="pascal" inline>math.floor</syntaxhighlight>}} - round down | ||
+ | * [[Frac|<syntaxhighlight lang="pascal" inline>frac</syntaxhighlight>]] - returns the fractional part of a floating point value | ||
+ | * [[Trunc|<syntaxhighlight lang="pascal" inline>trunc</syntaxhighlight>]] - round towards zero | ||
+ | * [[Int|<syntaxhighlight lang="pascal" inline>int</syntaxhighlight>]] - returns the integer part of a floating point value | ||
+ | * [[Div|<syntaxhighlight lang="pascal" inline>div</syntaxhighlight>]] - integer division | ||
+ | * [[Comparison of approaches for rounding to an integer]] |
Latest revision as of 17:17, 6 August 2022
│
Deutsch (de) │
English (en) │
Esperanto (eo) │
suomi (fi) │
русский (ru) │
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 4
See also
system.round
math.ceil
- round upmath.floor
- round downfrac
- returns the fractional part of a floating point valuetrunc
- round towards zeroint
- returns the integer part of a floating point valuediv
- integer division- Comparison of approaches for rounding to an integer