📄 prog2_08.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 + -