zoukankan      html  css  js  c++  java
  • c++ 保留小数

    precision()

    #include<iostream>
    using namespace std;
    
    int main()
    {
    float s=11.201    ;
    
    cout.precision(2);
                
    cout <<s<<endl;
    return 0;
    }
    View Code
    View Code

    #include<iostream>

    using namespace std;

    int main()

    {      float s=11.201 ;

    cout.precision(2);        

         cout <<s<<endl;

    return 0;

    }

     

    #include<iostream>
    using namespace std;
    
    
    int main()
    {
        ;
    float t=10001.119;
    cout.precision(2);
                
    cout <<t<<endl;
    return 0;
    }
    View Code

    #include<iostream>

    using namespace std;

    int main()

    {  

    float t=10001.119;

    cout.precision(2);   

              cout <<t<<endl;

    return 0;

    }

    *******************************************************************************************************************************************

    #include<iostream>
    using namespace std;
    
    int main()
    {
    float s=11.201    ;
    
    cout.precision(2);
     cout.setf(ios::fixed);           
    cout <<s<<endl;
    return 0;
    }
    View Code

    #include<iostream>
    using namespace std;
    
    
    int main()
    {
        ;
    float t=10001.119;
    cout.precision(2);
        cout.setf(ios::fixed);        
    cout <<t<<endl;
    return 0;
    }
    View Code

    ****************************************************************************************************************************************************

    #include<iostream>
    using namespace std;
    
    
    int main()
    {
        
    float s=11.201;
    
    cout<<fixed;    
    cout.precision(2);
            
    cout <<s<<endl;
    return 0;
    }
    View Code

    #include<iostream>
    using namespace std;
    
    
    int main()
    {
        
    float t=10001.119;
    cout<<fixed;    
    cout.precision(2);
                  
    cout <<t<<endl;
    return 0;
    }
    View Code

    *****************************************************************************************************************************************************

    #include<iostream>
    #include <iomanip>
    using namespace std;
    
    
    int main()
    {
        
    float s=11.201;
    
    cout<<fixed<<setprecision(2) <<s<<endl;   
    
            
    
    return 0;
    }
    View Code

    #include<iostream>

    #include <iomanip>

    using namespace std;

    int main()

    {  

    float s=11.201;

    cout<<fixed<<setprecision(2) <<s<<endl;  

           

    return 0;

    }

    #include<iostream>
    #include <iomanip>
    using namespace std;
    
    
    int main()
    {
        
    float t=10001.119;
    
    cout<<fixed<<setprecision(2) <<t<<endl;   
    
            
    
    return 0;
    }
    View Code

    #include<iostream>

    #include <iomanip>

    using namespace std;

    int main()

    {  

    float t=10001.119;

    cout<<fixed<<setprecision(2) <<t<<endl;  

           

    return 0;

    }

  • 相关阅读:
    浅析Go中的MPG模式(一)
    panic: assignment to entry in nil map
    Golang 新手可能会踩的 50 个坑
    小刘的go面试题
    go 单元测试整理
    go test 测试单个文件和测试单个函数
    mac pro锁屏后没有声音了怎么处理
    go json返回时间字符串处理time.Time类型
    php求一个字符串中不重复的最长子串
    业务订单号生成算法,每秒50W左右,不同机器保证不重复,包含日期可读性好
  • 原文地址:https://www.cnblogs.com/2014acm/p/3887422.html
Copyright © 2011-2022 走看看