Precision and decimal points

I need to program an arbitrary program that has to make use of setting precision to two decimal points, now I know that I can use "setprecision(n)" where n is the amount of significant figures, but how do I do it with an amount that I don't know the amount of digits to do it this way?

In delphi I believe you could just set the floating point to fixed, but I am not entirely sure as to how I would do that here.
1
2
3
4
5
6
7
#include <iostream>
#include <iomanip>
int main()
{
    std::cout << std::fixed << std::setprecision(2) << 10.1234 << '\n' <<
                 1234.56653 << '\n' << 0.74754;
}
gives
10.12
1234.57
0.75


http://en.cppreference.com/w/cpp/io/manip
http://en.cppreference.com/w/cpp/io/manip/fixed
http://en.cppreference.com/w/cpp/io/manip/setprecision
Topic archived. No new replies allowed.