9

同时搞定Android和iOS的Dart语言(3):数值类型

 4 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/107948347
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

同时搞定Android和iOS的Dart语言(3):数值类型

Dart语言的数值类型非常简单,只有两个类型:int和double。其中int表示64位整数类型,double表示双精度浮点数。int和double的基本用法如下:

一旦变量的数据类型确定为int,那么就不能将一个浮点数或其他类型的值赋给这个变量,例如,下面的代码会抛出编译错误。

在Dart语言中有一个num类型,该类型既可以表示int类型,也可以表示double类型。也就是说,如果将一个变量声明为num类型,那么该变量既可以赋int类型的值,也可以赋double类型的值,代码如下:

int类型支持十六进制表示法和科学计数法,代码如下:

下面的本例演示了内建数值类型更详细的用法。

运行结果如图1所示。

图1 数值类型用法演示

对本文感兴趣,可以加李宁老师微信公众号(unitymarvel):

关注  极客起源  公众号,获得更多免费技术视频和文章。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK