September 2017
Beginner
402 pages
9h 52m
English
There are four different methods that convert a Rat value to an integer: round, ceiling, floor, and truncate.
The round method rounds the value according to the mathematical definition: the value is rounded towards the closest integer. We can see that in the following code snippet:
say 3.14.round; # 3say 2.71.round; # 3
(Notice that the first dot separates the decimal part of the number, while the second dot is a method call.)
Negative values are also rounded so that the result is the closest integer number. We can see that in the following code snippet:
say (-3.14).round; # -3say (-2.71).round; # -3
The truncate method just cuts the decimal part, regardless of the sign, as follows:
say 3.14.truncate; # 3 ...