有时,我们需要输出确定小数位数的double,可以先引入如下头文件:

#include <iomanip>

然后通过下列方式输出:

double zzz = 8.66666;
cout << fixed << setprecision(2) << zzz << endl;

或者:

if ((aid % (int(allTime / deltaT) / files)) == 0) {
cout << fixed << setprecision(0) << double(curTime / allTime) * 100 << "% has been calculated..." << endl;
}