title: How to format CMFCPropertyGridProperty for float/double values
body: <p>I have several properties that are floats. By default, the CMFCPropertyGridProperty displays these with 6 decimal places. I want them to display with 2 decimal places as in <code>12.75</code> vs <code>12.750000</code>. So I put in the following line:</p>
  
  <pre><code>CMFCPropertyGridProperty::m_strFormatFloat = "%.2f";
  </code></pre>
  
  <p>That makes it display correctly with 2 decimal places. But when I change the value, <code>%.2f</code> is not a valid scanf format, so the program blows up.</p>
  
  <p>I tried overriding the <code>FormatProperty()</code> function like this:</p>
  
  <pre><code>class PropertyGrid2Digits : public CMFCPropertyGridProperty
  {
  public:
      PropertyGrid2Digits(const CString&amp; strName, const float InitialValue = 0, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0);
      virtual ~PropertyGrid2Digits();
      virtual CString FormatProperty() {
          CString str;
          str.Format("%.2f", GetValue().fltVal);
          return str;
      }
  };
  </code></pre>
  
  <p>but my version only gets called when the property is first created. Somehow, the <code>CMFCPropertyGridProperty::FormatProperty()</code> function gets called whenever the property gets painted.</p>
  
  <p>Does anybody know how I can fix this?
  Thanks!</p>