c++中double類型控制小數位數

  有時,咱們須要輸出肯定小數位數的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; }
相關文章
相關標籤/搜索