Home C++ Iostream Functions showpoint C++ showpoint Manipulator Definition In C++, showpoint makes a stream always print the decimal point of a floating-point number and keep its trailing zeros. By default 5.0 prints as 5. With showpoint it prints as 5.00000.
The number of digits comes from the precision of the stream, which is 6 significant digits by default. Change it with setprecision. It comes from <ios>, which <iostream> includes.
This is a manipulator . You do not call it on its own. You send it into a stream with << or >>, and it changes how that stream behaves from then on (or does one small job, like ending a line).
Syntax Put std::showpoint into the stream before the numbers.
std::cout << 5.0; // 5
std::cout << std::showpoint << 5.0; // 5.00000 Call What it does std::cout << std::showpointKeeps the point and trailing zeros. std::cout << std::showpoint << 5.0Prints 5.00000 with the default precision. std::cout << std::showpoint << std::setprecision(3) << 2.5Prints 2.50.
If you want a fixed number of digits after the point, fixed with setprecision is usually the better tool.
Library declarations ios_base& showpoint(ios_base& str); Parameters Parameter Description strThe stream. It is passed in for you when you write cout << showpoint. You never write this argument yourself.
Return Value Return Value Description ios_base&A reference to the same stream, so you can keep chaining << or >> after showpoint.
Important
showpoint counts significant digits , not digits after the point, unless fixed is on. So 100.0 with the default precision prints as 100.000. It affects floating-point numbers only. Integers are not changed.
C++ Examples 1. Trailing zeros 2. With precision 3. Integers unchanged Example 1 — Keep the Decimal Point and Zeros Compare a whole-valued double with and without showpoint.
#include <iostream>
int main() {
std::cout << 5.0 << '\n';
std::cout << std::showpoint << 5.0 << '\n';
return 0;
} How It Works By default the stream removes the useless .0, so 5.0 prints as 5. showpoint asks for the point to be shown and for zeros to be kept.The default precision is six significant digits, so 5.0 becomes 5.00000: one digit before the point and five after. Example 2 — showpoint with setprecision The precision decides how many digits are printed in total.
#include <iomanip>
#include <iostream>
int main() {
std::cout << std::showpoint << std::setprecision(3);
std::cout << 2.5 << '\n';
std::cout << 10.0 << '\n';
return 0;
} How It Works setprecision(3) allows three significant digits for every number.2.5 has two digits, so showpoint adds a zero and it prints as 2.50.10.0 already has two digits before the point, so only one zero is added: 10.0.Example 3 — Integers Are Not Affected Only floating-point numbers get a point.
#include <iostream>
int main() {
std::cout << std::showpoint;
std::cout << 10 << '\n';
std::cout << 100.0 << '\n';
return 0;
} How It Works 10 is an int. Integers have no decimal point, so showpoint does nothing to it.100.0 is a double. It must show six significant digits: three before the point and three after.That gives 100.000. If you want fewer zeros, lower the precision with setprecision. Frequently Asked Questions What does showpoint do in C++? It makes floating-point numbers always print a decimal point and keep trailing zeros, so 5.0 shows as 5.00000 instead of 5.
How many zeros does showpoint print? The precision decides it. By default there are 6 significant digits. Use setprecision to change that.
What is the difference between showpoint and fixed? showpoint counts significant digits in total. fixed counts digits after the decimal point. Use fixed with setprecision for money-like output.
Does showpoint change integers? No. Only floating-point types (float, double, long double) are affected.
How do I turn showpoint off? Use std::noshowpoint or cout.unsetf(std::ios::showpoint).
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
7 people found this page helpful
Helpful Share Copy link Suggestion