-
setprecision()
I have been tricked! setprecision() does not change the amount of decimals being printed out, it changes the amount of numbers to be printed out. E.g:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout<<setprecision(5)<<24.435166;
cin.get();
return 0;
}
Would output 24.435 (5 numbers) instead of 24.43517 (5 decimals).
printf() can do this simply by using %.5f, so how do you do it with cout?
-
before the cout add:
cout.setf(ios::fixed);
-
>setprecision() does not change the amount of decimals being printed out
As Thantos demonstrated, it does if you use fixed point:
Code:
cout << fixed << setprecision(5) << 24.435166;