-
Floating-point values are printed with exact fraction part, as specified by the precision.
-
In default notation format, the precision specifies max number of meaningful digits to display both before and after the decimal point.
-
The default precision is 6 digits.
-
This means that the value is rounded to the best approximation while using 6 digits.
-
If necessary, the default format may change to scientific notation to preserve most accurate representation.
|
-
Precision can be changed by calling precision( ) member function of the stream to improve data accuracy:
#include <iostream>
int main()
{
const double PI = 3.1415926;
std::cout.precision( 7 );
std::cout << PI << '\n';
return 0;
}
/*
Output: 3.141593
*/
|