Home C++ Iostream Functions noshowpoint C++ noshowpoint Manipulator Definition In C++, noshowpoint turns off showpoint. The stream goes back to its normal way of printing floating-point numbers: a decimal point appears only when it is needed, and trailing zeros are dropped.
That is why 5.0 prints as 5 and 2.50 prints as 2.5. 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::noshowpoint into the stream.
std::cout << std::showpoint << 5.0; // 5.00000
std::cout << std::noshowpoint << 5.0; // 5 Call What it does std::cout << std::noshowpointDrops the needless point and zeros. std::cout << std::noshowpoint << 5.0Prints 5. std::cout << std::noshowpoint << 2.50Prints 2.5.
If you need a fixed number of digits, use fixed and setprecision. noshowpoint is the opposite idea: show as few digits as possible.
Library declarations ios_base& noshowpoint(ios_base& str); Parameters Parameter Description strThe stream. It is passed in for you when you write cout << noshowpoint. 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 noshowpoint.
Important
noshowpoint is the default state of a stream. It will not remove zeros that are needed, such as the zeros in 100, and it does not round the number. The number of digits still comes from the precision.
C++ Examples 1. Turn it off 2. Trailing zeros 3. A list of values Example 1 — Switch showpoint Off Print the same number in both modes.
#include <iostream>
int main() {
std::cout << std::showpoint << 5.0 << '\n';
std::cout << std::noshowpoint << 5.0 << '\n';
return 0;
} How It Works showpoint is on, so 5.0 shows the point and five zeros.noshowpoint turns that off in the middle of the program.The second 5.0 prints as the short form 5. Example 2 — Drop the Trailing Zero A value like 2.50 loses its last zero.
#include <iomanip>
#include <iostream>
int main() {
std::cout << std::setprecision(3);
std::cout << std::showpoint << 2.5 << '\n';
std::cout << std::noshowpoint << 2.5 << '\n';
return 0;
} How It Works setprecision(3) allows three significant digits.With showpoint, the number is padded to three digits: 2.50. With noshowpoint, only the needed digits are printed: 2.5. Example 3 — Print Several Values in the Short Form Values with different numbers of decimals look clean without padding.
#include <iostream>
int main() {
double values[] = {1.0, 2.5, 3.25};
std::cout << std::noshowpoint;
for (double v : values) {
std::cout << v << ' ';
}
std::cout << '\n';
return 0;
} How It Works The array holds three values with zero, one, and two decimals. With noshowpoint, each number is printed with only the digits it needs. The result is 1 2.5 3.25. With showpoint all three would be padded to the same number of digits. Frequently Asked Questions What does noshowpoint do in C++? It turns off showpoint, so floating-point numbers print without a needless decimal point and trailing zeros.
Is noshowpoint the default? Yes. A new stream already uses it, so you only need it after showpoint.
How do I print 5.0 as 5 in C++? Just print it with the default settings, or use noshowpoint if showpoint was turned on before.
Does noshowpoint round the number? No. The precision of the stream still limits the digits, but noshowpoint itself only removes padding.
How do I always keep two decimals instead? Use std::fixed with std::setprecision(2).
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.
10 people found this page helpful
Helpful Share Copy link Suggestion