#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    double q =15.14259863;

    cout << showpoint       << q << endl;       //默认输出六位有效数字
    cout << setprecision(3) << q << endl;       //定义输出有效位数字
    cout << showpoint       << q  << endl;
    cout << setprecision(7) << q << endl;
    cout << showpoint       << q << endl;
    return 0;
}

浅学showpoint、setprecision和fixed的代码笔记

 

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    float i;
    double j;
    i = 10/3.0;
    j = 10/3.0;
    cout << fixed;               //让浮点型固定以数字的方式显示
    cout << setprecision(5);     //控制显示的小数位数
    cout << i << "  " << endl;
    cout << setprecision(8);
    cout << j << "  " << endl;
    return 0;
}

浅学showpoint、setprecision和fixed的代码笔记 

 

相关文章:

  • 2022-03-04
  • 2021-07-18
  • 2021-06-17
  • 2022-12-23
  • 2021-07-05
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-12-28
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案