Function to format double values to a string


/ Published in: C++
Save to your folder(s)

This function shows how you can format a double value to a string with a given precision.


Copy this code and paste it in your HTML
  1. std::string formatToString(int precision, double dValue)
  2. {
  3. CString sTmpVal;
  4. CString sFormat;
  5. sFormat.Format("%%.%df", precision);
  6. sTmpVal.Format(sFormat, dValue);
  7. return static_cast<LPCSTR>(sTmpVal);
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.