How to show decimal points

Hi,

I'm practicing with the following program and I cannot make it to show more decimal points other than 78.5, in other words I would like to show 78.5374984741 instead of just 78.5

Can someone be so kind and tell me how can I show the whole number when the program below runs?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    float radius = 5;
    float circleArea;
    float pi = 3.14;

      circleArea = pi * (radius* radius);  
      cout << "The area is: " << setprecision(13)<< circleArea << endl;

    system("pause");
    return 0;
}


Thanks a lot
it's showing 78.5 because 5*5*3.14 is 78.5

Did you want it to show 78.5000000000?


EDIT:

Setprecision only shows significant digits unless you explicitly tell it you want to show as fixed point. So if you want it to show trailing zeros, you need to make output fixed:

 
cout << "The area is: " << setprecision(13) << fixed << circleArea << endl;
Last edited on
Well, what I'm trying to do is to get the are of a circle where the radius is 5 and I want to show a more precise number, in this case I think it should be 78.5374984741

Thanks a lot for your reply!
My bad, I just changed my pi to 3.1415 and I got the number I was looking for.

Sorry I thought I tried this before posting and it didn't work!

Thanks a lot though
Topic archived. No new replies allowed.