Replies: 1 comment
-
Hi @QINZHAOYU - there's currently no support for specifying precision per column (we can maybe consider adding..) however one can control all double conversions to string. This conversion is used for all SetCell, SetColumn, SetRow calls. If you're working on an existing CSV file/stream, we can Get and Set just one column, and thus have only it affected. Example setting fixed precision of 2 decimal places: #include <iostream>
#include <vector>
#include "rapidcsv.h"
namespace rapidcsv
{
template<>
void Converter<double>::ToStr(const double& pVal, std::string& pStr) const
{
std::ostringstream out;
out << std::fixed << std::setprecision(2) << pVal;
pStr = out.str();
}
}
int main()
{
const std::string& csv =
"Date,Open,High,Low,Close,Volume,Adj Close\n"
"2017-02-24,64.529999,64.800003,64.139999,64.620003,21705200,64.620003\n"
"2017-02-23,64.419998,64.730003,64.190002,64.620003,20235200,64.620003\n"
"2017-02-22,64.330002,64.389999,64.050003,64.360001,19259700,64.360001\n"
"2017-02-21,64.610001,64.949997,64.449997,64.489998,19384900,64.489998\n"
"2017-02-17,64.470001,64.690002,64.300003,64.620003,21234600,64.620003\n"
;
std::stringstream instream(csv);
rapidcsv::Document doc(instream);
std::vector<double> column = doc.GetColumn<double>("Open");
doc.SetColumn<double>("Open", column);
std::stringstream outstream;
doc.Save(outstream);
std::cout << outstream.str();
} Expected output:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, how can i set precision while write a column with
double
data to .csv file?Beta Was this translation helpful? Give feedback.
All reactions