< cpp‎ | io‎ | ios base
streamsize precision() const;
streamsize precision( streamsize new_precision );

Manages the precision (i.e. how many digits are generated) of certain numeric output conversions.

1) Returns the current precision.

2) Sets the precision to the given one.


[edit] Parameters

new_precision - new precision setting

[edit] Return value

the precision before the call to the function

[edit] Example

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


The  default precision is 6
With default precision d is 1.23457
With high    precision d is 1.23456789012

[edit] See also

manages field width
(public member function)