Task. In Perl, the program has a variable which is a number. You need to round it
to the nearest whole in the smaller side. I.e. in the case of non-negative numbers this means
you just need to cut off the entire fractional part.
Here are some examples of values. All these numbers must be converted to number
The best way to solve this problem is to use the function
floor from the library
POSIX comes with Perl, so if you have Perl, this library is available to additionally install nothing.
Here is a sample program:
my $number = 10.3;
The program will display the number 10.
floor (in English this word is translated as "sex") is fairly standard. In many programming languages there is a function with the same name and which works exactly the same.
In addition to the functions
floor there is still a function of
ceil ("ceiling"), which rounds a number to the nearest integer in a big way.
floor for negative numbers works the same way as for positive numbers — rounds
the number to the nearest integer.
All of these numbers when using
floor will become the number