main() { // 1、Number与String转换 var num1 = 123; String str0 = num1.toString(); print(str0 is String); //true //2、String与Number转换 String str = '123'; var myNum = int.parse(str); print(myNum is int); //true String str2 = '123'; var myNum2 = double.parse(str2); print(myNum2 is double); //true //使用try catch处理异常 var str3 = ""; try { var myNum3 = double.parse(str3); print(myNum3); } catch (err) { print(err); //FormatException: Invalid double print(20); //20 } // 3、其他类型转换为Booleans类型 var str4 = ''; print(str4.isEmpty); //true var myNum4 = 2; print(myNum4 == 0); //false print(myNum4==null);//false var myNum5=0/0; print(myNum5.isNaN);//true }