Menu
CoddyTech

双精度浮点数(double)

本课属于 Coddy Dart 学习旅程的“基础知识”单元。第 8 课,共 94 课。

双精度数(double 类型)是带小数点的数字。

void main() {
  double price = 19.99;
  print(price);
}

可以在计算中使用双精度数:

void main() {
  double temperature = 72.5;
  print(temperature);
  
  // 提高温度
  temperature = 75.8;
  print(temperature);
  
  // 再创建一个 double 变量
  double increase = 2.5;
  
  // 将两个 double 值相加
  double newTemperature = temperature + increase;
  print(newTemperature);
}
challenge icon

挑战

入门

在 Dart 中创建一个处理 double 值(小数)的程序:

  1. 声明一个名为 temperature、值为 98.6 的 double 变量
  2. 声明一个名为 weight、值为 7.5 的 double 变量
  3. 为这两个变量打印带有描述性标签的值

输出必须与预期格式完全一致:
Temperature: temperature 

Weight: weight 

亲手试试

void main() {
  // 在这里声明你的 double 变量
  double temperature = ?;
  double weight = ?;
  
  // 输出变量及其标签
  print("Temperature: " + temperature.toString());
  print("Weight: " + weight.toString());
}
quiz icon自我测试

这节课包含一个小测验。开始学习即可作答,并记录你的进度。

基础知识中的所有课

自己练习: Dart 在线编译器