有两种方法来写 第一种 引入头文件 #include <iomanip> 输出 //保留几位,括号里数字就填几 cout<<setiosflags(ios::fixed)<<setprecision(2); 第二种 直接c输出 printf("%.2f", f);