wanna divide 2 numbers and get the result like this:
5 / 2 = 2.50
But it only outputs 2.
I don\'t now what i\'m doing wrong.
Here my code:
You have to use float
or double
variables, not int
(integer) ones. Also note that a division between two integers will lead to an integer result, meanwhile a division between a float
/double
and an integer will lead to a float result. That's because C implicitly promote this integer to float
.
For example:
5/2 = 2
5/2.0f = 2.5f
Note the .0f
, this actually means that we are dividing with a float.