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;

}

 

 

 

 

posted @ 2014-08-02 20:19  2014acm  阅读(607)  评论(0编辑  收藏  举报