# How can I have a variable set to the percent that a point is in between 2 other points?

I hope the question makes sense. Basically, I want a variable, lets say it is called “Percent”. I also have 3 objects, one called min, one called max, and one called MovingObject. MovingObject is represented by the colored points on the picture, and min and max are the ones labeled min and max. So basically, I want Percent to be set to the positioning of MovingObject in relation to min and max. So if it is half way in between min and max, it will be 50%, or 0.5(YELLOW), or any positioning would be set accordingly.
_
If you provide an answer, just use ([Object].transform.localPosition.x) for the positioning.
_

Since I have no code from you to work on, I’ll just use x_low, x_high and x (the yellow item).

First, you need the distance between the possible extremes.

``````float dist = x_high - x_low;
``````

This assumes that x_high is greater than x_low, which it should be.

Next, you need the offset from the low potential to the target (x).

``````float v = x - x_low;
``````

Again, x is assumed to be greater than x_low, which is to say between the two potential extremes. I use v because this is a vector from x_low to the target position x.

Now, you’re ready to produce the ratio, as long as you check that dist is > 0 first (which I just assume here).

``````float r = v / dist;
``````

This is a ratio, which is to say 1.0 equates to 100%. If you want a percentage you simply multiply r by 100.0f;