Dividing numbers that will result a float ?
#1

I know this may be a noob question... But...

pawn Код:
printf("%f", 2 / 10);
It prints 0.00000... Why ?
Reply
#2

pawn Код:
printf("%d", 2 / 10);
I think this doesn't need to be a float.
Reply
#3

Quote:
Originally Posted by HY
Посмотреть сообщение
pawn Код:
printf("%d", 2 / 10);
I think this doesn't need to be a float.
It will result 0 too.
As 2 / 10 will result in a fraction.
Reply
#4

Код:
printf("%.2f", 2.0 / 10.0);
Reply
#5

Let the compiler know that you want float result, by setting at least one constant to float:


pawn Код:
printf("%.2f", 2.0 / 10);
(the precision format (.2 part) is not required for this to work)
Reply
#6

my bad
printf("%.2f", 2.0 / 10.0);

2 and 10 must be floates also
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)