⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog2_08.cpp

📁 c++经典理论课程源文件程序.第二部分源程序
💻 CPP
字号:
// Program 2.8 Experimenting with floating point output
#include <iostream>
#include <iomanip>
using std::setprecision;
using std::fixed;
using std::scientific;
using std::cout;
using std::endl;

int main() {
  float value1 = 0.1f;
  float value2 = 2.1f;
  value1 -= 0.09f;                        // Should be 0.01
  value2 -= 2.09f;                        // Should be 0.01

  cout << setprecision(14) << fixed;      // Change to fixed notation
  cout << value1 - value2 << endl;        // Should output zero

  cout << setprecision(5) << scientific;  // Set scientific notation
  cout << value1 - value2 << endl;        // Should output zero

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -