I'm trying to find out how to get the right format when using ofstream when writing to CSV-file.
When writing small numbers e.g. doubles, i want them to look like this 0.00001, and in this way be editable in excel insted of a string that looks like this 1e+5.
1 2 3 4 5 6 7 8
// pringing the coefficients to file
ofstream outFile;
outFile.open("coefficients.csv");
for (i=0;i<(n-1);i++){
outFile << a[i] <<";"; // printing coefficients to CSV-file x^0,x^1,x^2,x^3,....
}
outFile << a[i] <<"\n"; // printing last coefficients with \n
outFile.close();
It is correctly formatted but my question is why outFile << fixed << setprecision(3); seems to give no result. In this case I suppose the result sould have been
cannot reproduce your issue, provide a testcase.
(note that even setprecision seems to be ignored)
> In this case I suppose the result sould have been
> -1.10e+264
no, that would be scientific with precision 2.
with fixed the result would be -1099999999999999947870924204796281072930243270295235333075692513449338536873729360514597640642232230440436671725593239765694799667225685575602696107581347649216914041553581821371143774609356580328172724615114283621647556821177718905263019987496412950478790496092160.000
no matter what you do in the text file, excel may choose to reformat it for you when it displays it. CSV does NOT store the column type, so excel just takes a best guess at the cell data types, you can over-ride this by converting to xls and setting each column to what you need.