how to get percents from 2 numbers
#1

so I have tried this:
new percents = floatround( num1 / num2 * 100 );
but everytime I do this it returns 0, espect if num1 = num2 it returns 100
so maybe someone knows how to do this in pawn.
also tried without floatround function but no success
Reply
#2

What do you wanna do?
Reply
#3

Yes, it does return 0 because inside the floatround function you have 3 integers, if you want to do that, you should use this
Quote:

floatround( float(num1)/num2 * 100);

now, num1 becomes a float, so you have at least one floating number in that operation, and it is enough. (when you divide a float with an int or vicevers the result it's a float, in your code you divide 2 integers, and the result is 0 if num1<num2)

BUT!

why not simply do this:
Quote:

new percents = num1*100 / num2;

?
Reply
#4

Here you go mate

pawn Код:
floatround((num1/num2)*100)
Reply
#5

thanks to GaByM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)