I am working on a C ++ program with a large number of numbers that are double types (values ββin millions and billions with just a couple of places to the right of the decimal point). I do the calculations on these numbers and then print the result into text / CSV files. I noticed that in text files all my numbers are rounded (up to six digits). So the value 13,169,911 is displayed as 13,169,900 in my output file.
Is this rounding only on print? To get the total number of digits in a variable, I just need to specify something when I write to a file? I have included sample code to write to the file below:
void PrintPropFinance(vector<PropFinance>& PF, int NumProps, int Iterations, int ForecastLength, string CurDeal, string ModelRunID, string ScenName, Assumptions& Ass) { string filename; ofstream OutFile; ostringstream s1; s1 << BASEPATH << "Output/" << CurDeal << "_" << ModelRunID << "_" << ScenName << "_PropFinance" << ".csv"; filename = s1.str(); OutFile.open(filename); // Put in the column headers first OutFile << "PropID" << "," << "Item" << "," << "StartDate" << "," << "NumOfPeriod" << "," << "Result" << "," << "Isap" << "," << "CurLoanBal" << "," for (int i=1; i<=NumProps; ++i) { // Populate the single-vector variables OutFile << PF[i].PropID << "," << PF[i].Item << "," << PF[i].StartDate << "," << PF[i].NumOfPeriod << "," << PF[i].Result << "," << PF[i].Isap << "," << PF[i].CurLoanBal << "," << endl; } OutFile.close(); } // Prop finance class definition class PropFinance { public: string PropID; int Item; string StartDate; int NumOfPeriod; string Isap; double CurLoanBal; }
source share