12.02.2013, 03:02
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.
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.
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.
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:
Hope, you have learned something by reading this. If you have any question, please post below. Thanks!
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.. |
(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 |
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 |
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!