Course of Raku / Essentials / Data type conversion

Converting types using constructor forms

A similar method is to construct a new instance of an object of the required type by calling its constructor, whose name is the name of the type. For example:

my $n = Int('1.23E4');
say $n;      # 12300
say $n.WHAT; # (Int)

Here, the string containing a floating-point number is converted to an integer.

Course navigation

Data type conversion / Converting types using type coercion methods   |   Data type conversion / Converting types with prefix operators


💪 Or jump directly to the exercises to this section.