You don’t need the cast, but you need to use a number indicating that you are a float
somehow. Both the 8
, as to the 2
as to the 3
are integer numbers, so when he does the calculations they will generate integer numbers, there is no cast implied just because it had a division that could potentially give a decimal part. If you want the decimal part then say this.
#include <stdio.h>
void main() {
printf("O resultado eh: %.2f", 8.0 * 2.0 / 3.0);
}
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
Need to put the decimal part in all? In this case does not need, but has case that may need because of precedence and associativity. If you’re working with float
use literals that are already float
.
'Cause you’re splitting by
3
and not by3.0
... Dor = 8*2/3.0;
.– thxmxx