c++ - Using stringstream precision to format floats but discarding zero-padding -
i'm trying set precision (i.e. number of decimal places) of floats , long doubles 10, don't want them 0 padded. i.e.,
123456.789123456789 should give 123456.7891234568, 123456 should not give 123456.0000000000, rather 123456
so far i've narrowed down to:
long double mynumber; string mystring; ostringstream mystream; mystream.setf(ios::fixed,ios::floatfield); mystream.precision(10); mystream << mynumber; mystring = mystream.str();
i've tried fiddling setfill(' ') , std::ws can't hang of it. suggestions?
don't use ios::fixed
ios::floatfield
. that's causes padding. use setprecision
.
Comments
Post a Comment