//Works on Dartpad
main() {
var pi = 3.14; //3.14159265359
var numbers = 0;
dynamic result = 1.2;
while (result.runtimeType == double) {
numbers++;
result = numbers * pi;
}
print('$result / $numbers = $pi');
}
//Works on local
main() {
var pi = 3.14; //3.14159265359
var numbers = 0;
dynamic result = 1.2;
while ((result - result.truncate()) != 0) {
numbers++;
result = numbers * pi;
}
print('${result.truncate()} / $numbers = $pi');
}
问题是每当你初始化一个双精度变量时,当它变成一个整数时,dartpad 可以将它转换为一个整数,但本地编译器不会这样做。会不会是js造成的?因为据我所知 dartpad 是用 js 编译的。