I'm making a custum slider.

I have two numbers...

Min = 120

Max = 400

I want:

120 = 0%

400 = 100%

I don't know the equation for this.

I want create a percentage to a custom range... How do i do it?

7 posts
• Page **1** of **1**

Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).

**Posts:**3,858**Reputation:**158,422

B

71
S

22
G

288
blackhornet wrote:Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).

Humm cool. i will use, but when i want:

-100 = 0%

0 = 100%

what do i do?

**Posts:**81**Reputation:**2,241

B

14
S

6
G

2
woah what complications, how about this:

x = Min + (random() * ((Max - Min) + 1))

1st problem = minimum is 280, maximum 420.

same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.

same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

perc = (x /(max+min))*100

x = Min + (random() * ((Max - Min) + 1))

1st problem = minimum is 280, maximum 420.

same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.

same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

perc = (x /(max+min))*100

Sea Monsters template - Isometric

Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705

Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705

**Posts:**630**Reputation:**9,465

B

43
S

14
G

12
blackhornet wrote:You always want a number between 0 and 1, and 0 to be the starting point, so add 100. That gives you 0 to 100. Divide by 100 to get the factor (0to1). Do your math, multiply by 100, then subtract 100 again, to move everything back into range.

Thanks

**Posts:**81**Reputation:**2,241

B

14
S

6
G

2
saiyadjin wrote:woah what complications, how about this:

x = Min + (random() * ((Max - Min) + 1))

1st problem = minimum is 280, maximum 420.

same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.

same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

perc = (x /(max+min))*100

Hey, perfect! Thank you!

**Posts:**81**Reputation:**2,241

B

14
S

6
G

2
7 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: No registered users and 0 guests |