stringstream and numbers

The code below will explain better what i want:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
#include <sstream>

int main()
{
	double num0 = 541.4;
	double num1 = 541.456;
	std::stringstream sstr;
	sstr << std::setprecision(2) << std::setbase(10) << "num0 = " << num0 << "\nnum1 = " << num1 << std::endl;
	std::cout << sstr.str();

	std::cin.get();
	return 0;
}


output:
1
2
num0 = 5.4e+002
num1 = 5.4e+002


desired output:
1
2
num0 = 541.40 //add 0 to end
num0 = 541.45 //removed 6 


how to obtain that format of numbers in stream string?

Thanks for your time.

EDIT: like sprintf_s function does with:
1
2
char buffer[128];
sprintf_s(buffer, 128, "%.2f", num0);
Last edited on
That's it, thanks.
Topic archived. No new replies allowed.