# Equation/method to get number that's closest to and higher than a target number

#### mmh9119

Hi to all,

Should be straight forward.

Lets say I have a figure, 0.13.

Suppose I have a target number, 1.

I want to arrive to at the number that's closest to and higher than the target number (1 in this example). If I multiply 0.13 by 8, I get 1.04 which satisfies the condition (closest to and above the target number).

However, is there any equation or method I can use to arrive at 1.04 without me knowing beforehand that multiplying 0.13 by 8 gives us 1.04?

More importantly, is it possible to write said equation as syntax? I basically want this to try and streamline a code which involves increasing an animation's frames by its speed, and subsequently trigger an action once a certain frame was reached. The animation would play frame 0 while the the image index (the counter to check which frame was being played) would increment by the image speed (0.13 in our example). So between image index 0 and 0.99, the first frame would play, between index 1 and 1.99, the second frame would play etc. Right now I have to calculate manually in my head or by using a calculator, the precise value for the intended frame in which the action would trigger (no ranges are allowed). Was wondering if the math could allow for streamlining the checking.

Thanks!

#### romsek

Math Team
$\text{Let's represent your 0.13 by$b$and your target by$T$, and the factor you want to compute by$k$}\\ \text{So$(k-1)b < T < kb$}\\ k = \left \lfloor \dfrac{T}{b}\right \rfloor+1\\ \text{Where$\lfloor x \rfloor$is the largest integer less than or equal to$x$}\\ \text{This is a commonly supplied function in programming languages and is usually called Floor(x)}$

#### mmh9119

Thank you for the reply @romsek .

Forgive my ignorance, but if I plug-in in the values for T and b in that function, I am not able to arrive at the expected value (1.04 or 8).

Is there some other way to get either value?

#### romsek

Math Team
Thank you for the reply @romsek .

Forgive my ignorance, but if I plug-in in the values for T and b in that function, I am not able to arrive at the expected value (1.04 or 8).

Is there some other way to get either value?
$\left \lfloor \dfrac{1}{0.13}\right \rfloor +1 = 7+1 = 8$

$8 \cdot 0.13 = 1.04$

I don't see what the problem is.

#### mmh9119

Apologies, the figure I got was 7.69 + 1 = 8.69

8.69 * 0.13 = 1.13