[Tutorial] How to make use of percentage
#1

Introduction:
In this tutorial, I will show you how to make use of the percentage. Suppose, you want to take 25% of a player's full cash or want to decrease the player's full cash by 25%. This is how you do it.




What is a percentage?:
A percentage is a number or a ratio as a fraction of 100. So, 4 percentage means 4 per cent which means 4 per 100 which means 4/100 in algebra which is equal to 0.04. You can use the % sign to abbreviate the percentage. So, let's face some real life SA-MP problems while scripting and overcome it.



Quote:

dude... lololo... how to get 25% of $1500... plz halp..

Alright, seems like this dude got kicked out of school based on his English so he couldn't study what percentage is. Let's teach him shall we? So, what do we know from there? We know the percentage and the value. To get the 25% of 1500 we simply do this equation:

(Value/100) * Percentage

In our case, it would be:

(1500/100) * 25 = 375(Remember B.O.D.M.A.S)

So, the 25% of $1500 is $375. Simple isn't it? Let's do another one.


Quote:

tsk tsk tsk.... i hate my life lol how do you take away 16% of $3200

Yet another dude kicked out from school. Great! Now, we need to take 16% of 3200. How do we go about doing it?
Let's first see what we know. We know the percentage and we know the value. We want to decrease the value by the percentage. We can do that by using this equation:

(1.0 - (Percentage / 100)) * Value

In our case it would be:

(1.0 - (16 / 100)) * 3200
= (1.0 - 0.16) * 3200
= 0.84 * 3200
= 2688

So, if we take away 16% of $3200, it would be $2688. It's kinda fun to see what you can do with percentages. The main thing is the probability which I will show it now.

Quote:

man.. i flipped the coin 18 times and got heads 7 times. Whats the percentage of it
Let's put the numbers in the appropriate variables:

Total Flips: 18
Heads: 7


Let the total flips be t and the heads be h. Now let's see the equation in action:

(Value / Total) * 100

In our case it would be:

(h/t) * 100
= (7/1 * 100
= 38.8%


I personally don't like decimals which comes to the point where I explain what floor and ceiling is.

So, basically this is what it is:

Value 38.8

Ceiling- Denotes the decimal point and increases the value by 1.
39

Floor- Denotes the decimal point and doesn't change the value.
38


This is just a rough explanation of what both of those things are. For more info checkout mathisfun.


There are times when you work with float values instead of integer value. That doesn't mean that the equation will change.

For example:
(5/10) * 100

You would have float instead of whole numbers. Here's what you will do:
pawn Code:
new Float:fVal = 5.0, Float:fTotal = 10.0; // Assigning the variables
new Float:fPercentage = (fVal/fTotal) * 100.0; // Same equation just dealing with floats instead.
new percentage = floatround(fPercentage, floatround_floor); // Convert the float to a whole number int.


Hope, you have learned something by reading this. If you have any question, please post below. Thanks!
Reply
#2

bedmas not bodmas lol
exponents
Reply
#3

Quote:
Originally Posted by mastermax7777
View Post
bedmas not bodmas lol
exponents
There are no exponents. B.O.D.M.A.S is a simple order of operation which stands for Bracket Of Division Multiplication Addition and Subtraction.
Reply
#4

We learned P.E.M.D.A.S.

Anyways, nice tutorial.

An easy way to remember is using cross multiplication with proportions.

Ex:

54/100 = x/1600
54 * 1600 = 100x
86400 = 100x
x = 864

Same shit, different pile.
Reply
#5

Quote:
Originally Posted by VincentDunn
View Post
We learned P.E.M.D.A.S.

Anyways, nice tutorial.

An easy way to remember is using cross multiplication with proportions.

Ex:

54/100 = x/1600
54 * 1600 = 100x
86400 = 100x
x = 864

Same shit, different pile.
Yeah, I used P.E.M.D.A.S on high school but I remember B.O.D.M.A.S pretty clearly. An equation can be written in multiple ways and the equation you use is based on personal preferences. Will make Triginometry tutorial tomorrow as I remember the famous quote which says "“In learning you will teach, and in teaching you will learn.”.
Reply
#6

Cool! I've always been fascinated with trig. Found this small webpage that explains sin/cos functions to get coords in front of a player. http://badgersa-mp.webs.com/SA-MP/Ge...tOfPlayer.html Perhaps something you could elaborate on.
Reply
#7

Quote:
Originally Posted by VincentDunn
View Post
Cool! I've always been fascinated with trig. Found this small webpage that explains sin/cos functions to get coords in front of a player. http://badgersa-mp.webs.com/SA-MP/Ge...tOfPlayer.html Perhaps something you could elaborate on.
Thanks for that link. Will show examples on how it can be used on player's camera and the stuff mentioned on that link.
Reply
#8

So BODMAS is used on brackets, orders while PEMDAS, on parenthesis, exponents and etc?
I don't know BODMAS as we use PEMDAS

EDIT
Also, instead of the formula (Value/100) * Percentage
You can take the decimal value of the percentage and multiply it to the value

25% of $1500
You can also use the decimal value:

.25 * $1500

They have pretty much the same result, although I find this much simpler to use.



GJ Learned something today.
Reply
#9

Thanks for this, gotta learn percentages.
Reply
#10

I use this a lot, and it is awesome: (Make use of this setting/style):

Quote:

Given something ----- (worth, is, costs, etc) --- This much
New to be found out value ====== Unknown?

Then,
Except the unknown, just cross multiply and you get the answer. It's much easier to remember, and helps a lot.
Example:
From 18, if I get 7 heads, what's the percent?
So:

Quote:

If 18 === 100 percent
7 === x percent.

Therefore,
Quote:

7*100/18 = 700/18

= 38.888
Works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)