一、类型
数值型有 num,int, double
num a = 10; a = 12.5; print(a); print(a.runtimeType); int b = 20; // b = 20.5; print(b); print(b.runtimeType); double c = 10.5; // c = 30; print(c); print(c.runtimeType); print(" ");
其中,runtimeType 为运行时的类型。
输出如下:
12.5 double 20 int 10.5 double
二、运算
print(b + c); print(b - c); print(b * c); print(b / c); print(b ~/ c); print(b % c);
其中,~/ 为取整,%为取余
输出如下:
30.5
9.5
210.0
1.9047619047619047
1
9.5
三、数值常见的一些方法
//NaN print(0.0 / 0.0); //isEven 是否是偶数 print(b.isEven); //isOdd 是否是奇数 print(b.isOdd); int d = 11; print(d.isEven); print(d.isOdd); int e = -100; //绝对值 print(e.abs()); double f = 10.5; print(f.round());//最靠近f的整数 print(f.floor());//不大于f的最大整数 print(f.ceil());//不小于f的最小整数 print(f.toInt()); print(f.toString()); print(d.toDouble());
输出如下:
NaN true false false true 100 11 10 11 10 10.5 11.0
Dart学习系列文章:https://www.cnblogs.com/jukaiit/category/1636484.html