Posted By

bits on 02/28/11


Tagged

format String double


Versions (?)

Function to format double values to a string


 / Published in: C++
 

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

  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  

You need to login to post a comment.