SA-MP Forums Archive
Percentage issues ? - 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: Percentage issues ? (/showthread.php?tid=120272)



Percentage issues ? - Kyosaur - 10.01.2010

There seems to be some problems when ever i try to subtract a certain percentage from a number, is anyone else having this problem? I made this small function just to test, but it doesn't seem to be working, it always prints 0 for some reason. I know the math is right, but pawn just wont do it correctly for some strange reason (is it due to SALING_LOSE_PERCENT/100 equaling a float value ?). Im just completely out of ideas.

Help pl0x ?

pawn Код:
stock TestSell(pricee)
{
  printf(" **** %d", ((SALING_LOSE_PERCENTAGE/100)*pricee)); //SALING_LOSE_PERCENTAGE = 50 and pricee = 100
  return 1;
}



Re: Percentage issues ? - dice7 - 10.01.2010

50/100 = 0.5 and integers get rounded down, so It's 0


Re: Percentage issues ? - Puffmac - 10.01.2010

You need to use Floats, since decimal places are involved.


Re: Percentage issues ? - Kyosaur - 10.01.2010

Quote:
Originally Posted by dice7
50/100 = 0.5 and integers get rounded down, so It's 0
Quote:
Originally Posted by Puffmac
You need to use Floats, since decimal places are involved.
I thought that might be the case. Even when i convert everything to floats, it still gives a wrong answer. Instead of zero though, its giving me 1112014848 now lol. argh, i never imagined 5th grade material would be such a nightmare.




Re: Percentage issues ? - Finn - 10.01.2010

%d ----> %f


Re: Percentage issues ? - Kyosaur - 10.01.2010

Quote:
Originally Posted by Finn
%d ----> %f
lmfao, thank you. I must be drunk.


Re: Percentage issues ? - iLinx - 11.01.2010

you could also cast as a float, try
Код:
printf(" **** %d", ((float)(SALING_LOSE_PERCENTAGE/100)*pricee));
dunno if its possible in pawn, im sure it is though