Course of Raku / Essentials / More about types / Data type conversion / Exercises / Fractional part
Solution: Fractional part
To get the fractional part of a number, you can subtract the integer
part, which you can get by casting the number to an
Int.
Code
The possible solution is shown below:
my $n = 15.8972;
say $n - $n.Int;🦋 Find the program in the file fractional-part.raku.
Output
$ raku exercises/coercion/fractional-part.raku
0.8972Comment
Try the same program with negative numbers too, for example:
my $n = -15.8972;
say $n - $n.Int;In this case, the result should also be correct:
$ raku exercises/coercion/fractional-part.raku
-0.8972Course navigation
← Fractional part | Quiz: What is its type? →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська