保留小数,但会四舍五入

#include<bits/stdc++.h>
using namespace std;
main()
{double a=2.9939;
    
    cout<<fixed<<setprecision(2)<<a;printf("%.3f", a);

    printf("%.2lf",a);
return 0;
}

原文地址:https://www.cnblogs.com/tyhj/p/9053602.html