floor(x)

x = Any number.

 

This function rounds down (as in 'down to the floor') the number to the nearest whole number, so wholenumber in Example #1 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.

 

Example #1:

wholenumber = floor(10.4);

 

Example #2:

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;

}

 

(See the switch statement for further details on switch).

 

Revision #1