以下2個函數着重於帶*註釋的行。當語句執行時,不會顯示小數位。 3021680380/10000000變爲302.而不是302.1680。錯誤地使用SetPrecision
void convert(){
setprecision(4); //************************
newFileTime = new double[numRec]; //***********
newOffset = new int[numRec];
newSize = new int[numRec];
newNum = new int[numRec];
newType = new int[numRec];
newTime = new int[numRec];
for(int i = 0; i<numRec; i++){
newFileTime[i] = fileTime[i]/10000000; //**********
newOffset[i] = offset[i]/512;
newSize[i] = fileSize[i]/512;
newNum[i] = 0;
if(type[i] == "Write"){
newType[i] = 0;
}else{
newType[i] = 1;
}
newTime[i] = responseTime[i]/10000000;
}
}
void exports(){
setprecision(4); //**************
ofstream fout;
fout.open("prxy_0.ascii");
{
if(!fout){
cout <<"File opening failed. \n";
}
}
fout<< numRec <<endl;
for(int i = 0; i < numRec; i++){
fout<< newFileTime[i] << " " << newNum[i] << " " << newOffset[i] << " " << newSize[i] << " " << newType[i] << " " << newTime[i];
cout<< fileTime[i] << " " << newFileTime[i] <<endl; //**********
if(i != numRec - 1){
fout<<endl;
}
}
fout.close();
}
任何想法?
編輯標題停止指責經過良好測試的庫代碼。 – djechlin
這不是你如何使用'setprecision()'。見http://www.cplusplus.com/reference/iomanip/setprecision/ – NPE
它可能不是傳統的,但它的作品 – theB3RV