Archived

This topic is now archived and is closed to further replies.

Austrian Coder

std::setprecision

Recommended Posts

Hi! I have a problem with std::setprecision. Lookt at this: std::stringstream stream; stream << std::setprecision(2) << std::fixed << Number[1] << " Euro | " << std::setprecision(Kommastellen) << std::fixed << Number[2] << " Cent | "; Number[1] = 125,4 Number[2] = 12 Now the output is: 125,40 Euro | 12,00 Cent But i need this output: 125,40 Euro | 12 Cent How can i reset the setprescision? Thanks, Christian

Share this post


Link to post
Share on other sites
Check the value of Kommastellen.

const std::streamsize old = stream.precision(); // save current

stream << std::setprecision(2) << std::fixed << Number[1] << " Euro | " << std::setprecision(0) << std::fixed << Number[2] << " Cent | ";

stream.precision(old); // restore


Regards Mats

Share this post


Link to post
Share on other sites