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;

    }

  • 相关阅读:
    RedHat7安装NetCore环境并发布网站
    【WPF学习】第四十二章 透明
    细说枚举
    js获取ip地址,操作系统,浏览器版本等信息,可兼容
    js实现数据流(日志流,报警信息等)滚动展示,并分页(含实现demo)
    js实现点击copy,可兼容
    js实现htmlToWordDemo
    H5 web 存储之 Webstorage
    已发布的WEB项目,如何挂在服务器或者本机的IIS下
    Nuget打包没有注释显示
  • 原文地址:https://www.cnblogs.com/2014acm/p/3887422.html
Copyright © 2011-2022 走看看