Floor
What is it?
Similar to the Ceil function discussed above, the Floor function takes a single numeric argument and, if it includes a decimal point, rounds the number. Instead of rounding up to the nearest integer, the Floor function instead rounds down to the nearest integer instead.
What is the Syntax?
The Floor function’s syntax is as follows:
Floor( Argument );
Why might I want to use this?
The miller from the Ceil function example above has expanded his operation and now employs a large workforce to produce many times the amount of flour he did previously. It is now more cost effective to simply fill as many 1kg bags with flour as he can, and anything left over is either discarded or recycled.
To calculate how many bags of flour he will fill, we can apply the Floor function, stripping out the fraction of flour leftover once the mill has finished its bagging process:
NumberOfBags := Floor( KilogramsOfFlour );
On Monday the mill produces 5,642.97kg of flour. Floor(5,642.97) = 5,642 bags.
On Tuesday the mill produces 4,971.33kg of flour. Floor(4,971.33) = 4,971 bags.
On Wednesday the mill produces 5,866.67kg of flour. Floor(5,866.67) = 5,866 bags.
In total the mill needs 16,479 bags to contain the flour produced between Monday and Wednesday.
As with the Ceil function, the miller could also bag up all the flour in one go, which would require using the Floor function against the total amount:
Floor( 5642.97 + 4971.33 + 5866.67 );
This expression will let him know that he requires 16,480 bags of flour.
<< Previous: Ceiling (Ceil) | Next: Random (Rnd) >>