1. 程式人生 > >VS2012中用cout輸出float和double型別資料

VS2012中用cout輸出float和double型別資料

今天在用C++程式設計的時候,發現用cout輸出的float和double型別精度有問題

float fTest=1;
double dTest=1;
cout<<fTest<<endl;
cout<<dTest<<endl;
cout<<showpoint<<fTest<<endl<<showpoint<<dTest<<endl;
cout<<showpoint<<setprecision(16)<<fTest<<endl<<showpoint<<setprecision(16)<<dTest<<endl;
cout<<sizeof(fTest)<<endl;
cout<<sizeof(dTest)<<endl;

執行效果如下