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;

    }

  • 相关阅读:
    [Python]计算豆瓣电影TOP250的平均得分
    [Golang]使用自建代理访问指定网站
    HDU 2689.Sort it-冒泡排序
    HDU 1728.逃离迷宫-BFS
    hihoCoder #1498.Diligent Robots
    POJ 2503.Babelfish-sscanf()函数+strcmp()函数+二分
    Codeforces 608 B. Hamming Distance Sum-前缀和
    Codeforces 608 A. Saitama Destroys Hotel
    sscanf()函数
    UVA 11461.Square Numbers
  • 原文地址:https://www.cnblogs.com/2014acm/p/3887422.html
Copyright © 2011-2022 走看看