首页 > 代码库 > c++ 保留小数

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;

}