數值型有 num,int, double spa
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("\n");
其中,runtimeType 爲運行時的類型。code
輸出以下:blog
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);
其中,~/ 爲取整,%爲取餘class
輸出以下:方法
30.5
9.5
210.0
1.9047619047619047
1
9.5im
//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());
輸出以下:runtime
NaN true false false true 100 11 10 11 10 10.5 11.0