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 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 |
|
|
|
|
|
-- should give -2 |
|
|
|
|
|
|
|
-- should give -2 |
|
|
|
|
|
|
|
-- should give 0 |
|
|
|
|
|
|
|
-- should give 0 |
|
|
|
|
|
|
|
-- should give 2 |
|
|
|
|
|
|
|
-- should give 2 |
|
|
|
|
|
|
|
-- list all table array elements |
|
|
|
|