how to get percents from 2 numbers - 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)
+--- Thread: how to get percents from 2 numbers (
/showthread.php?tid=646918)
how to get percents from 2 numbers -
JustNothing - 26.12.2017
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
Re: how to get percents from 2 numbers -
Lucases - 26.12.2017
What do you wanna do?
Re: how to get percents from 2 numbers -
GaByM - 26.12.2017
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;
|
?
Re: how to get percents from 2 numbers -
Lucases - 26.12.2017
Here you go mate
pawn Код:
floatround((num1/num2)*100)
Re: how to get percents from 2 numbers -
JustNothing - 26.12.2017
thanks to GaByM