- Perl 6 Deep Dive
- Andrew Shitov
- 97字
- 2021-07-03 00:05:51
Converting to an Int value
To convert the Rat value to an integer value, call the Int method. This is the general principle for type conversion: data types define the methods whose names repeat the names of other data classes.
my $x = 10/3;
say $x.Int; # 3
In this program, the result of $x.Int is 3, but you should keep in mind that 10/3 in the assignment is not a division, but a way to express a Rat number. The same can be done using a more explicit form, as shown here:
my $x = <10/3>;
推薦閱讀
- 軟件項目管理(第2版)
- C語言程序設計習題解析與上機指導(第4版)
- Python 深度學習
- Mastering matplotlib
- 編程數學
- Integrating Facebook iOS SDK with Your Application
- Java網絡編程實戰
- MySQL 8從零開始學(視頻教學版)
- Kotlin語言實例精解
- Mastering Object:Oriented Python(Second Edition)
- Elastix Unified Communications Server Cookbook
- Java程序設計及應用開發
- Visual FoxPro程序設計實驗教程
- Illustrator CS6中文版應用教程(第二版)
- 軟件測試項目實戰之功能測試篇