prog2_08.cpp
来自「一本语言类编程书籍」· C++ 代码 · 共 24 行
CPP
24 行
// 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 + =
减小字号Ctrl + -
显示快捷键?