zoukankan      html  css  js  c++  java
  • setprecision **fixed

    复制代码
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main( void )
    {
        const double value = 12.3456789;
    
        cout << value << endl; // 默认以6精度,所以输出为 12.3457
        cout << setprecision(4) << value << endl; // 改成4精度,所以输出为12.35
        cout << setprecision(8) << value << endl; // 改成8精度,所以输出为12.345679
        cout << fixed << setprecision(4) << value << endl; 
        // 加了fixed意味着是固定点方式显示,所以这里的精度指的是小数位,输出为12.3457
        cout << value << endl; // fixed和setprecision的作用还在,依然显示12.3457
        cout.unsetf( ios::fixed ); // 去掉了fixed,所以精度恢复成整个数值的有效位数,显示为12.35
        cout << value << endl;
        cout.precision( 6 ); // 恢复成原来的样子,输出为12.3457
        cout << value << endl;
        cout<<fixed<<value<<endl;
        cin.get();
        return 0;
    } 
    复制代码
  • 相关阅读:
    元组类型
    字符串类型
    列表类型
    python 循环
    python语句
    python运算符
    python1
    软件管理
    rpm yum
    LVM
  • 原文地址:https://www.cnblogs.com/wangsicongde/p/7598732.html
Copyright © 2011-2022 走看看