Round: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Round
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 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 [[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. | |
| 2 | + | ||
| 3 | + | ## Declaration | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | function Round(X: Real): int64; | |
| 7 | + | ``` | |
| 8 | + | ||
| 9 | + | ## Example Usage | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 12 | + | begin | |
| 13 | + | WriteLn( Round(8.7) ); | |
| 14 | + | WriteLn( Round(8.3) ); | |
| 15 | + | // examples of "bankers rounding" - .5 is adjusted to the nearest even number | |
| 16 | + | WriteLn( Round(2.5) ); | |
| 17 | + | WriteLn( Round(3.5) ); | |
| 18 | + | end. | |
| 19 | + | ``` | |
| 20 | + | ||
| 21 | + | ### Output | |
| 22 | + | ||
| 23 | + | ` 9`\ | |
| 24 | + | ` 8`\ | |
| 25 | + | ` 2`\ | |
| 26 | + | ` 4` | |
| 27 | + | ||
| 28 | + | ## See also | |
| 29 | + | ||
| 30 | + | - [`system.round`](https://www.freepascal.org/docs-html/rtl/system/round.html) | |
| 31 | + | - [`math.ceil`](https://www.freepascal.org/docs-html/rtl/math/ceil.html) - round up | |
| 32 | + | - [`math.floor`](https://www.freepascal.org/docs-html/rtl/math/floor.html) - round down | |
| 33 | + | - [[Frac|frac]] - returns the fractional part of a floating point value | |
| 34 | + | - [[Trunc|trunc]] - round towards zero | |
| 35 | + | - [[Int|int]] - returns the integer part of a floating point value | |
| 36 | + | - [[Div|div]] - integer division | |
| 37 | + | - [[Comparison of approaches for rounding to an integer]] | |
| 38 | + | ||
| 39 | + | --- | |
| 40 | + | *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](/wiki-contact).* |
