A
Anjo Gasa
I'm having some cases where setprecision in combination with iostreams
gives some unepected behavior. Consider the following program:
#include <iostream>
#include <iomanip>
int _tmain(int argc, _TCHAR* argv[])
{
float value = 0.063397526741027832;
std::cout << value << std::endl;
std::cout << std::setprecision( 7 ) << value << std::endl;
std::cout << fixed << value << std::endl;
std::cout << std::scientific << value << std::endl;
}
which gives the following output:
0.0633975
0.06339753
0.0633975
6.3397527e-002
The first line makes sense (the default precision is 6), the second
line adds a digit of precision in response to the setprecision(7)
call, the third line calls for a fixed output and as a result seems to
only give 6 digits of precision. The final lines seems to give 8
digits of precision. When using scientific is the "precision" of the
number refer to digits right of the decimal point. But why when using
fixed and a precision of 7, does it only give 6 digits of precision.
Anjo
Anjo
gives some unepected behavior. Consider the following program:
#include <iostream>
#include <iomanip>
int _tmain(int argc, _TCHAR* argv[])
{
float value = 0.063397526741027832;
std::cout << value << std::endl;
std::cout << std::setprecision( 7 ) << value << std::endl;
std::cout << fixed << value << std::endl;
std::cout << std::scientific << value << std::endl;
}
which gives the following output:
0.0633975
0.06339753
0.0633975
6.3397527e-002
The first line makes sense (the default precision is 6), the second
line adds a digit of precision in response to the setprecision(7)
call, the third line calls for a fixed output and as a result seems to
only give 6 digits of precision. The final lines seems to give 8
digits of precision. When using scientific is the "precision" of the
number refer to digits right of the decimal point. But why when using
fixed and a precision of 7, does it only give 6 digits of precision.
Anjo
Anjo