Similar topic is already discussed in the forum. But I have some different problem in following code:
double total;
cin >> total;
cout << fixed << setprecision(2) << total;
If I give input as 100.00
then program prints just 100
but not 100.00
How can I print 100.00
?
setprecision
specifies the minimum precision. Sowill print 1.2
fixed
says that there will be a fixed number of decimal digits after the decimal pointwill print 1.20
This will be possible with setiosflags(ios::showpoint).
Using header file
stdio.h
you can easily do it as usual like c. before using %.2lf(set a specific number after % specifier.) using printf().It simply printf specific digits after decimal point.
It is possible to print a 15 decimal number in C++ using the following:
The easiest way to do this, is using cstdio's printf. Actually, i'm surprised that anyone mentioned printf! anyway, you need to include the library, like this...
This will print the value of "total" (that's what
%
, and then,total
does) with 2 floating points (that's what.2f
does). And the\n
at the end, is just the end of line, and this works with UVa's judge online compiler options, that is:the code you are trying to run will not run with this compiler options...