Round
The Round function converts a number to the nearest integer.
CRect:Round() |
The number x is rounded to integer n if (n – 0.5) <= x < (n + 0.5). Half integers n+0.5 are rounded up or down in the standard way to avoid statistical bias. The strategy correctly extends across the 0 boundary to negative numbers.
The following script lists the rounded values of some numbers in the range -3 through +3. You can run this script and modify it to test rounding on your machine.
|
-- create a table to hold the values |
|
-- rounds to -3 |
|
-- rounds to -3 |
|
-- rounds to -2 |
|
-- rounds to -2 |
|
-- rounds to -2 |
|
-- rounds to -2 |
|
-- rounds to -2 |
|
-- rounds to -1 |
|
-- rounds to -1 |
|
-- rounds to -1 |
|
-- rounds to 0 |
|
-- rounds to 0 |
|
-- rounds to 0 |
|
-- rounds to 0 |
|
-- rounds to 0 |
|
-- rounds to 1 |
|
-- rounds to 1 |
|
-- rounds to 1 |
|
-- rounds to 2 |
|
-- rounds to 2 |
|
-- rounds to 2 |
|
-- rounds to 2 |
|
-- rounds to 2 |
|
-- rounds to 3 |
|
-- rounds to 3 |
|
|
|
-- list all table array elements |
|
|
|
|