SA-MP Forums Archive
Dividing numbers that will result a float ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Dividing numbers that will result a float ? (/showthread.php?tid=555742)



Dividing numbers that will result a float ? - Ahmad45123 - 08.01.2015

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

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


Re: Dividing 'undividable' numbers ? - HY - 08.01.2015

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


Re: Dividing 'undividable' numbers ? - Ahmad45123 - 08.01.2015

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.


Re: Dividing numbers that will result a float ? - CoaPsyFactor - 08.01.2015

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



Re: Dividing numbers that will result a float ? - Misiur - 08.01.2015

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)


Re: Dividing numbers that will result a float ? - CoaPsyFactor - 08.01.2015

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

2 and 10 must be floates also