SA-MP Forums Archive
Very Very Very Strange ??? - Calculate bug? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Very Very Very Strange ??? - Calculate bug? (/showthread.php?tid=206298)



[SOLVED]Very Very Very Strange ??? - Calculate bug? - Jeffry - 03.01.2011

Hello guys,

I wanted to calculate some jackpot things, like 9/10, but pawno didn't do this:

Test:
pawn Код:
printf("%0.2f", 9/10);
printf("%0.2f", 9/100);
printf("%0.3f", 9/1000);
printf("%0.4f", 9/10000);
printf("%0.9f", 9/100);
printf("%f", 9/1000);
printf("----------");
printf("%0.2f", 5/3);
printf("%0.9f", 9*0.01);  //Same as: 9/100, just with multiplicate
And I get:
pawn Код:
[17:20:51] 0.00
[17:20:51] 0.00
[17:20:51] 0.000
[17:20:51] 0.0000
[17:20:51] 0.000000000
[17:20:51] 0.000000
[17:20:51] ----------
[17:20:51] 0.00
[17:20:51] 0.089999996
=> Well, the last one is nearly correct, but the others fail.

Have I done something wrong, or is this a pawno bug?
I'd be happy about help, or people who could test this themself, if they have the same problem.


Jeffry


Re: Very Very Very Strange ??? - Calculate bug? - JaTochNietDan - 03.01.2011

Perhaps this would be because you're dividing an integer and not a float. You should try:

pawn Код:
printf("%0.2f", 9.0/10);
Or better, use the Floatdiv function.


Re: Very Very Very Strange ??? - Calculate bug? - Babul - 03.01.2011

printf("%0.3f",floatdiv(9,1000));


Re: Very Very Very Strange ??? - Calculate bug? - Jeffry - 03.01.2011

Ah, Thanks alot guys. Both works, but the result is like the 'printf("%0.9f", 9*0.01);' (0.089999996), but floatround will do it. ^^
Thanks again, and have a nice evening.

Jeffry