std::ios_base::precision

Manages the precision (i.e. how many digits are generated) of floating point output performed by std::num_put::do_put.

# Declarations

streamsize precision() const;
streamsize precision( streamsize new_precision );

# Parameters

# Return value

The precision before the call to the function

# Example

#include <iostream>
 
int main()
{
    const double d = 12.345678901234;
    std::cout << "The  default precision is " << std::cout.precision() << "\n\n";
    std::cout << "With default precision d is " << d << '\n';
    std::cout.precision(8);
    std::cout << "With high    precision d is " << d << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 189C++98‘precision’ was defined as ’the number of digits afterthe decimal point’, but it is not correct in some casescorrected

# See also