Skip to content

How can i set precision while write a column with double data to .csv file? #151

Closed Answered by d99kris
QINZHAOYU asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by d99kris
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants