title: c++: How do I format a double to currency with dollar sign?
body: <p>I have a function that takes a double and returns it as string with thousand separators. You can see it here: <a href="https://stackoverflow.com/questions/7276826/c-format-number-with-commas">c++: Format number with commas?</a>  </p>
  
  <pre><code>#include &lt;iomanip&gt;
  #include &lt;locale&gt;
  
  template&lt;class T&gt;
  std::string FormatWithCommas(T value)
  {
      std::stringstream ss;
      ss.imbue(std::locale(""));
      ss &lt;&lt; std::fixed &lt;&lt; value;
      return ss.str();
  }
  </code></pre>
  
  <p>Now I want to be able to format it as currency with a dollar sign.  Specifically I want to get a string such as "$20,500" if given a double of 20500.</p>
  
  <p>Prepending a dollar sign doesn't work in the case of negative numbers because I need "-$5,000" not "$-5,000".</p>