GM: floor
From GMpedia.org Wiki
|
floor | |
| Type: | function |
| Arguments: | 1: value |
| Limitations: | none |
- The correct title of this article is floor(). It appears incorrectly here because of technical restrictions.
The floor() function in Game Maker is a mathematical function where the input argument is always rounded to the nearest integer less than the argument.
[edit] Examples
This function rounds down (as in 'down to the floor') the number to the nearest whole number, so wholenumber in the example below would return 10. This function is particularly useful when checking for random numbers, because random(x) can return a real number (5.65, 10.3,etc), you can use floor to round the number to a whole number.
wholenumber = floor(10.4);
In general:
round(4.120213) will return 4 round(4.6585) will return 4
[edit] In conjunction with random
A popular example is:
selection = floor(random(3)) switch (selection) { case 0: // 0 was selected because if it was 0.x, it would be rounded down break; case 1: // 1 was selected because if it was 1.x, it would be rounded down break; case 2: // 2 was selected because if it was 2.x, it would be rounded down break; }
[edit] See Also
Content from Game Maker Knowledge Base, was used to expand this article. The content was contributed by nickydude.

