Is there a convinient way to format a double into a string?

Basically I would like to have the format as "0.###"

which means it shows up to 3 decimals if they are all non-zero. Otherwise it won't display the decimal at all.

For instance,

1234.56789 --> 1234.568
1234.56989 --> 1234.57
1234.99951 --> 1235
1234.00049 --> 1234

Ideally it would also do comma separate as 100,000,000 for 100 million.

Thanks.
No there is no magical standard way of formatting the code as you seem to desire. You'll need to write code to do the formatting.

Use a stringstream, then carry out additional manipulation of the resulting string
1
2
3
4
    ostringstream os;
    os.precision(3);
    os << fixed << n;
    string temp = os.str();
Topic archived. No new replies allowed.