0

I am converting price to a string and this needs to output two decimal places for to_string(). How do I do that?

string Antique::toString()
{
    string info = name + ": " + " $" + to_string(price); 

    return info;
}
acraig5075
  • 10,588
  • 3
  • 31
  • 50
Gman
  • 1
  • 2
    Use `ostringstream` with `fixed` + `setprecision(2)`. [Related](https://stackoverflow.com/questions/16280069/show-two-digits-after-decimal-point-in-c) – rafix07 Mar 01 '20 at 20:38
  • What is the type of `price`? If it's a floating point type (`float` or `double`) expect some rounding errors. – Bob__ Mar 02 '20 at 14:50

0 Answers0