streamsize precision() const; | (1) | |
streamsize precision( streamsize new_precision ); | (2) |
Manages the precision (i.e. how many digits are generated) of floating point output performed by std::num_put::do_put
.
The default precision, as established by std::basic_ios::init
, is 6.
new_precision | - | new precision setting |
the precision before the call to the function.
#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.precision(12); std::cout << "With high precision d is " << d << '\n'; }
Output:
The default precision is 6 With default precision d is 1.23457 With high precision d is 1.23456789012
manages field width (public member function) |
|
changes floating-point precision (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/io/ios_base/precision