Hi All,
I am new to C++ programming. I encounter an unexpected behavior of
'setprecision'.
The code snippet is :
#include <iostream.h>
#include <stdio.h>
#include <iomanip.h>
int main()
{
long double ld=1234567890.1 234567898;
int prec = 0;
prec = cout.precision( );
cout<<"Precisio n : "<<prec<<en dl;
cout.flags(ios: :fixed);
cout << setprecision(10 ) << ld << endl;
prec = cout.precision( );
cout<<"Precisio n : "<<prec<<en dl;
return 0;
}
The output I was expecting was :
Precision : 6
1234567890.1234 567898
Precision : 10
But the output that was produced is :
Precision : 6
1234567890.1234 567000
Precision : 10
What happened to the last 3 digits of the variable I am trying to
print.
Why is it filling zeros in the last three places? Is there any reasong
behind that?
Please enlighten me on this issue.
Thanks in Advance,
Mahesh K U