Hello,
I am trying to caluclate the percentage, i am doing
float percentage;
float number1;
float number2;
percentage = (number1 / number2) * 100;
However percentage is always 0 because it is not giving me the answer to 2 dp. I know you can use cout << setprecision(2) << percentage << endl;
but i am not outputting percentage straight away - i am passing the variable to another function before outputting.
Any ideas on how to solve this?
Thanks for your help
jim
I am trying to caluclate the percentage, i am doing
float percentage;
float number1;
float number2;
percentage = (number1 / number2) * 100;
However percentage is always 0 because it is not giving me the answer to 2 dp. I know you can use cout << setprecision(2) << percentage << endl;
but i am not outputting percentage straight away - i am passing the variable to another function before outputting.
Any ideas on how to solve this?
Thanks for your help
jim