SA-MP Forums Archive
How to get precents of a value? - 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: How to get precents of a value? (/showthread.php?tid=276655)



How to get precents of a value? - KfirRP - 14.08.2011

For example getting 15% of some numeric value. I saw servers doing that. How?


Re: How to get precents of a value? - PhoenixB - 14.08.2011

Format Strings
Placeholder Meaning
%b Inserts a number at this position in binary radix
%c Inserts a single character.
%d Inserts an integer (whole) number
%f Inserts a floating point number.
%i Inserts an integer.
%s Inserts a string.
%x Inserts a number in hexadecimal notation.
%% Inserts the literal '%'

I've never seen that anywhere though


Re: How to get precents of a value? - swieberdevos - 14.08.2011

The way i know:

part of amount : full amount x 100 = percent.

pawn Код:
24 / 153 * 100 = 15,7%



Re: How to get precents of a value? - antonio112 - 14.08.2011

I'll give you an example:
pawn Код:
new moneys, percent;

moneys = GetPlayerMoney(playerid)
percent = (moneys * 15) / 100
That's how you calculate 15 percent. If you want 7 percent (for example), replace 15 with 7.


Re: How to get precents of a value? - iPLEOMAX - 14.08.2011

The Value you have divided by 100 and then multiplied by how much percent you want.
(Value / 100) * %

> You have 10,500 $
> You want it's 18%
> Use this: (10500/100) x 18
= 1,890$

> You have 1,457,811 $
> You want it's 56%
> Use: (1457811/100) x 56
= 816,374$

pawn Код:
stock ToPercentage(value, percentage)
{ return (value/100)*percentage; }

//Now you can use ToPercentage(5500, 15);
//It will return 15% of 5,500



Re: How to get precents of a value? - KfirRP - 14.08.2011

Thanks everybody. This can be locked / archived or w/e. No need in help anymore. Just math. Havent thought about it anyways thanks