- 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>;
推薦閱讀
- Node.js 10實戰(zhàn)
- 潮流:UI設(shè)計必修課
- Android Jetpack開發(fā):原理解析與應(yīng)用實戰(zhàn)
- Mastering Concurrency in Go
- OpenStack Orchestration
- Apache Kafka Quick Start Guide
- SQL Server數(shù)據(jù)庫管理與開發(fā)兵書
- Getting Started with Eclipse Juno
- Machine Learning for OpenCV
- 微前端設(shè)計與實現(xiàn)
- Three.js Essentials
- 前端程序員面試算法寶典
- The Java Workshop
- Visual Basic 程序設(shè)計實用教程
- Developing Windows Store Apps with HTML5 and JavaScript