Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I take a percentage out of value?

Asked by 4 years ago

Hello, I wanna take a percentage out of a value and then add it to another value, The problem is that I don't know how. I searched all over the internet and found only how to get one value from a table with a percentage but thats not what I want.

Help Would Be Really Appreciated

0
value1*Percentage/100 + value2 theking48989987 2147 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

In programming, we almost never work with percentages directly. To subtract say, 50% from variable A, you'd do A * 0.5. If we want to "move" 50%, we'll have to subtract half of A from itself, and then "give it" to B.In the example below I declare two doubles (a form of number), print out their values, set A to half its value, and set B to its value plus half of A. Both doubles are then printed again, and at this point will equal 50 and 75 respectively.

local A = 100
local B = 25
print(A, B)
A, B = A * 0.5, B + A * 0.5
print(A, B)
Ad

Answer this question