I and trying to have a float display a certian number past decimal point no matter if the number is 1.0 or 1.1 of 1.11 or 1.1111. I can't find anything that can help me in the cout statement. It can be 1 ,2 , 3 numbers past decimal point just need help on how to format output
for example:
e=(2*9)/2.1
the answer to this is 8.571428571
I can't figure out how to format the output so is displays up to 3 decimal places or maybe 2 or maybe one decimal place but i don't need he long answer.
example of the output i am looking for is 8.57
it helped but when it prints on screen i get 1 place after decimal point i need to have at least two show in some cases. it seems the out put is rounded up even if i don't want it to any help with that problem.
Thank you Bazzy for the help and any more you can give me.
for n digits enter this line towards beginning, keep in mind you can change it up throughout your program by adding the line where ever you need it re-adjusted.
cout << fixed << showpoint << setprecision(n);
n = how many decimal placed you want to show.
for example:
cout << fixed << showpoint << setprecision(8);
double n = 1/3;
cout << n << endl;
cout << fixed << showpoint << setprecision(7);
cout << n << endl;
cout << fixed << showpoint << setprecision(3);
cout << n << endl;
cout << fixed << showpoint << setprecision(6);
cout << n << endl;
cout << fixed << showpoint << setprecision(2);
cout << n << endl;
it would display
0.33333333
0.3333333
0.333
0.333333
0.33
Found my answer. Thank you for all your help. Now all i have to do is figure out how i get one answer using the formula and the place where i got the formula come up with different results but that is not your problem. Again thank you for your help