Very Very Very Strange ??? - Calculate bug?
#1

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
Reply
#2

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.
Reply
#3

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)