有时,咱们须要输出肯定小数位数的double,能够先引入以下头文件:spa
#include <iomanip>
而后经过下列方式输出:code
double zzz = 8.66666; cout << fixed << setprecision(2) << zzz << endl;
或者:blog
if ((aid % (int(allTime / deltaT) / files)) == 0) { cout << fixed << setprecision(0) << double(curTime / allTime) * 100 << "% has been calculated..." << endl; }