decimal places and Pow function in c++ -


Most really simple question, please keep any answer easier to understand that I am still quite new on this: / P>

I'm making a little app, and I need to use the powers for some calculations. After some research I found the pow function in the seminary and made a play. Lastly I came up with this snippet, which works:

  #include & lt; Iostream & gt; # Include & lt; Semith & gt; using namespace std; Int main () {float dummy 2, test (6.65); Dummy 2 = (float) p (float) 3.57, test); Cout & lt; & Lt; Dummy2; Return 0; }  

and gives the correct answer (4734.17), but at only two decimal places. I'd prefer 5 decimal places

What did I do wrong here? Am I using the wrong data type (floats)? Or is there a limit to what is it in the POW function to use only 2dp?

I can do this, if I have set the constant with only those values, because it is only going to be 4 or 5, it tells me that I need this precision, but If it is possible that this program would be great for him.

Thanks

I call FBIinder, and use doubles for more accuracy I do To solve your problem, you have two options, C-style and C ++ style.

C-style

  #include & lt; Cstdio & gt; Printf ("% .5f", dummy2);  

C ++ style

#include < Iomanip & gt; Std :: cout & lt; & Lt; Cetressification (5) & lt; & Lt; Dummy 2 & lieutenant; & Lt; Std :: endl;

OR

  std :: cout.precision (5); Std :: cout & lt; & Lt; Dummy 2 & lieutenant; & Lt; Std :: endl; // Continue using cout to output 5 decimal places  

Comments