# Get value between 2 point based on percentage

**URL:** <https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326>\
**Category:** C++\
**Tags:** logic, unreal-engine, CPP, question\
**Created:** [October 25, 2018, 9:54am UTC](https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326 "2018-10-25T09:54:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4be4a5e2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4be4a5e2](https://forums.unrealengine.com/u/anonymous_user_4be4a5e2)\
**Post date:** [October 25, 2018, 9:54am UTC](https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326/1 "2018-10-25T09:54:04Z")

</div>

Both points are float values and point **A** could be any numbers from 0.0 to 1.0, point **B** is a fixed value if this helps. now i want to find the value between point **A** and Point **B** by a given percentage.

- If by 0.7 i want a number that 70% of the way from point **A** to point **B** how should i do that?

here is what i currently do when point A starts from 0.0 :

```
float value = GivenPercent * MaxValue;

```

EDIT for clarification :  
An example of what I’m looking for would be if the given percentage was 40% i need to find the 40% of the way from A to B and A could be 0.6, B could be 1.0, so 0% will be 0.6 and 100% will be 1.0.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c120ce39](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c120ce39](https://forums.unrealengine.com/u/anonymous_user_c120ce39)\
**Post date:** [October 25, 2018, 10:13am UTC](https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326/2 "2018-10-25T10:13:45Z")

</div>

Let’s establish some basic premise:

Vector Example

A=0%= Vector 0,0,0

B=100%=Vector 20,20,20

Input =0.8=Expected Vector 16,16,16

B_Input = 20,20,20_0.8 = 16,16,16.

* * *

Integer Example

A=0

B=50

Input=0.675

B_input=50_0.675=33.75

* * *

So your formula is:  
B\*Input

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4be4a5e2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4be4a5e2](https://forums.unrealengine.com/u/anonymous_user_4be4a5e2)\
**Post date:** [October 25, 2018, 10:47am UTC](https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326/3 "2018-10-25T10:47:44Z")

</div>

Thanks for answer but it wasn’t what I’m looking for, i know the formula when **A** is 0 as shown in my question, what i wanted was how do i calculate it if **A** was a non-zero value. if **A** value is 0.4 then 0 percent will be 0.4.

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [October 25, 2018, 10:59am UTC](https://forums.unrealengine.com/t/get-value-between-2-point-based-on-percentage/436326/4 "2018-10-25T10:59:31Z")

</div>

Use Lerp (linear interpolation)

```
float A = ...;
float B = ...;
float t = 0.7f; // 70%
float Result = FMath::Lerp(A, B, 0.7f);

```

Or you can code your formula by hand

```
float t = 0.7f;
float Result = A + (B - A) * t;
```
