+ 4
How to print floating value of only last 2 round points in c++?
Here suppose a is float a = 500/33; If now I print a with c++ code cout << a; It will print 15.1515 But I just want to print only 15.15 Only the last 2 digits after the frictional period. Is there any alternative? NB: I would not like to use printf function. https://code.sololearn.com/cOqhJD7ZY5nR/?ref=app
6 Antworten
+ 5
You forgot to
#include <iomanip>
+ 2
1. Multiply by 100
2. Convert to int
3. Divide by 100.0
+ 2
Yes, there are many more options, this was the simplest.
https://stackoverflow.com/questions/25925290/c-round-a-double-up-to-2-decimal-places
+ 2
How to print floating value of only last 2 round points in c++?
+ 1
I got a new idea. Thanks a lot.
cout << fixed << setprecision(2); cout << gpa; from this code.
+ 1
Problem solved.
https://code.sololearn.com/cOqhJD7ZY5nR/?ref=app