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

Simple math-related question?

Asked by 9 years ago

Hey guys, I need help with a rather simple math question . If 500 is 0 and 800 is 1, what is any value of x between those expressed as sort of a percent decimal between 0 and 1?

For instance, what is 630?

How do I find this ? I know it's basic math but I'm very tired right now.

This isn't entirely about scripting but it is definitely related to scripting for something I'm trying to do. Delete it if you must.

3 answers

Log in to vote
1
Answered by
Mystdar 352 Moderation Voter
9 years ago

There is a difference of 300, therefore 300 = 1 and 0 = 0, so you would do:

(x - 500)

To get what it could be.

Divided by 300 (For a fraction)

(x - 500)/300

Will give you a percentage

This script proves it:

while true do
    x = math.random(500, 800)
    print (x.."\'s decimal is"..((x - 500)/300))
    wait(1)
end

Output: 655's decimal is0.51666666666667

532's decimal is0.10666666666667

615's decimal is0.38333333333333

726's decimal is0.75333333333333

721's decimal is0.73666666666667

604's decimal is0.34666666666667

648's decimal is0.49333333333333

655's decimal is0.51666666666667

797's decimal is0.99

726's decimal is0.75333333333333

521's decimal is0.07

710's decimal is0.7

651's decimal is0.50333333333333

705's decimal is0.68333333333333

544's decimal is0.14666666666667

546's decimal is0.15333333333333

Ad
Log in to vote
0
Answered by 9 years ago
local endnum = 800
local startnum = 500

local x = 630

local result = x-startnum/(endnum-start)

630 would be about 0.433

Log in to vote
0
Answered by 9 years ago

Thanks guys you're awesome :)

Answer this question