Numbers after decimal point

So lets say i try to divide 10 by 3 (10 / 3) and the answer should be 3.33333(3)
how can i make the code to get me 4 numbers after decimal (3.3333)?
and tell me what i have to include :).

i got this:

int square;
square = ((b * b) - (4 * a * c));

Thanks !

EDIT: sorry, did not see beginner's forum :S.. i am a beginner
Last edited on
Integers can only store... well, integer numbers. If you want the post decimal point digits you will need to floats/ doubles.
can you like me more specific?

i tryed this

square = float((b * b) - (4 * a * c));

but it have me the same answer :S
You got to make "square" a double, so it can store decimals. Then, if you want it to display an excact number of decimals, use "setprecision()". For example:

1
2
double square = 10/3;
cout << setprecision(4) << square
Last edited on
Thank you! That was what i needed !
10/3 will still be an integer division because 3 and 10 are both integers.
You need to use a double literal to make it a double: 10.0 / 3; ( the 3 will be promoted to a double automatically )
i made exactly as Stupebrett said, but used Float instead of double
Topic archived. No new replies allowed.