Just use stream manipulators:
cout << setprecision(2) << fixed << centage;
Which will display 2 digits after the decimal point, as in fixed
notation the manipulator setprecision()
specifies the number of the digits after the decimal point.
I doubt that iostream
alone provides directly the facilities to temper with
decimal precision. So, in my opinion there is no simpler way besides the already provided manipulators.
The other unorthodox solution is to do something using string manipulation, where for example you can convert to string and concatenate some (meaningless) 0's till you get the wanted "precision" and return the result as string.