Percentage issues ?
#1

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

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

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

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.

Reply
#5

%d ----> %f
Reply
#6

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)