You need std::fixed
and std::setprecision
:
std::cout << std::fixed << std::setprecision(3) << a;
These require following header:
#include <iomanip>
More Related Contents:
- How can I pad an int with leading zeros when using cout
- how do I print an unsigned char as hex in c++ using ostream?
- Why uninitialized variable print a strange negative value? [duplicate]
- How do I print a double value with full precision using cout?
- How do I print out the contents of a vector?
- uint8_t can’t be printed with cout
- How do I print out the contents of a vector?
- Why is address of char data not displayed?
- cout
- ‘printf’ vs. ‘cout’ in C++
- C++ alignment when printing cout
- c++ force std::cout flush (print to screen)
- C++ cout hex values?
- C++ printing boolean, what is displayed?
- Why I cannot cout a string?
- Why does streaming a char pointer to cout not print an address?
- How to make C++ cout not use scientific notation
- cout or printf which of the two has a faster execution speed C++?
- Why is std::cout not printing the correct value for my int8_t number?
- Order of execution in operator
- How to print to console when using Qt
- How to make cout behave as in binary mode?
- Does std::cout have a return value?
- What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?
- Float formatting in C++
- Unbuffered output with cout
- Correctly over-loading a stringbuf to replace cout in a MATLAB mex file
- How do you set the cout locale to insert commas as thousands separators?
- How to use C++ std::ostream with printf-like formatting?
- Output aligned columns