Answers.Body: <p>The value of the text will recalculate on every frame, based on the value of your slider at that time, so if you've set the following values:</p>
  <pre><code>frame = 1  slider = 1
  frame = 20 slider = 2
  </code></pre>
  <p>then the value of the slider at frame 10 will be 1.5</p>
  <p>On frame 19 it will be 1.95 as that is the correct linear calculation of that value at that time.</p>
  <p>It might be easier if you make a new answer explaining exactly what you want to achieve.</p>
  <p>If you want only a single decimal place, you could do that like this:</p>
  <pre><code>slider = (effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value);
  output = (Math.round(slider * 10))/10;
  SourceText = output
  </code></pre>
  <p>The Math.round function (note the annoying capital 'M'), causes the number to round to the nearest whole number. Because you want decimal places, we multiply it up by ten inside the function, do the rounding, then divide it again after the rounding. Think of the number of zeroes in that line as the number of decimal places you want, ie if you wanted two decimal places, change the '10' values both to '100'.</p>
  <p>This will give you:</p>
  <pre><code>Frame = 1  text = 1.0
  Frame = 10 text = 1.5
  Frame = 19 text = 1.9
  Frame = 20 text = 2.0
  </code></pre>
  <p>If you wanted to keep the value rounded down until you hit frame 20, use Math.floor like this:</p>
  <pre><code>slider = (effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value);
  output = (Math.floor(slider));
  SourceText = output
  </code></pre>
  <p>Which gives:</p>
  <pre><code>Frame = 1  text = 1
  Frame = 10 text = 1
  Frame = 19 text = 1
  Frame = 20 text = 2
  </code></pre>
  <p>Or if you wanted to keep it rounded down to one decimal place:</p>
  <pre><code>slider = (effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value);
  output = (Math.floor(slider *10))/10;
  SourceText = output
  </code></pre>
  <p>Gives:</p>
  <pre><code>Frame = 1  text = 1.0
  Frame = 10 text = 1.5
  Frame = 19 text = 1.9
  Frame = 20 text = 2.0
  </code></pre>
  <p>You can also use the Toggle Hold function in your keyframes by right clicking a keyframe, and selecting 'Toggle Hold', which will hold your slider at a specific value if you need to.</p>
  <p>In general, every time I'm working with sliders for text expressions, I start with this expression:</p>
  <pre><code>slider = (effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value);
  tidying = (Math.round(slider * 100))/100;
  SourceText = &quot;$&quot; + tidying + &quot;bn&quot; +&quot;\r&quot; +&quot;DEBTS&quot;;
  </code></pre>
  <p>Which usually gets me close to what I need - it allows for rounding to two decimal places (the 100 values do this), text before the value (in this case a dollar sign), text after the value (&quot;bn&quot;), and a new line (created using &quot;\r&quot;), and text on the line beneath it (&quot;DEBTS&quot;).</p>
  <p>I think there are neater ways to do this now - take a look at <a href="https://ukramedia.com/4-different-ways-to-round-numbers-in-after-effects/" rel="nofollow noreferrer">these rounding techniques</a>, but this is the way I usually do it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-14T19:57:56.017Z
Answers.Text: This answers and explains it beautifully thank you. In the end I ended up adding one decimal point so that the number wouldn't round up prematurely. And to hide the decimal I just used a mask. My problem in this case is that my video is about a historical event and in my animation, I need the date to turn from 1520 to 1521 at an exact point in the animation. So when I put the keyframe in the exact location the number changes too early. Unfortunately the 'Numbers' effect doesn't help me because I can't set it back in time earlier than 1910. I'm gonna look into the things you sent.
Answers.UserDisplayName: Bengi Yardımlı
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-15T11:46:15.623Z
Answers.Text: use two hold keyframes on the two frames where you need them to switch - ie one at 1520, and one at 1521
Answers.UserDisplayName: tomh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-14T05:48:33.280Z
Answers.LastActivityDate: 2024-04-14T06:53:06.703Z
Answers.LastEditDate: 2024-04-14T06:53:06.703Z
Answers.UserDisplayName: tomh
Body: <p>Lets say i want to animate a number using a slider control and I want the number to be &quot;1&quot; on the first keyframe and on frame number 20 i want it to be &quot;2&quot;. Now if I place a keyframe on frame number 20, the number will change instead on frame number 10 as it is the halfway point. Intuitively I was expecting the animation to start counting the decimals after the first keyframe and finally on the last, after reaching 1,9 it would turn into 2 exactly on frame number 20. However it seems this isn't the case. I'm trying to use this method for animating a date counter on a historical video and it's important the date, lines up exactly with what's happening on the video. And constantly moving keyframes up and down will take a long time. Is there any other solution, or am I missing something.</p>
  
Tags: <after-effects>
Title: How to keyframe a slider control in After Effects
UserDisplayName: Bengi Yardımlı
ThreadText: # How to keyframe a slider control in After Effects
  
  (Asked by: username_0 on 2024-04-13)
  
  Lets say i want to animate a number using a slider control and I want the number to be "1" on the first keyframe and on frame number 20 i want it to be "2". Now if I place a keyframe on frame number 20, the number will change instead on frame number 10 as it is the halfway point. Intuitively I was expecting the animation to start counting the decimals after the first keyframe and finally on the last, after reaching 1,9 it would turn into 2 exactly on frame number 20. However it seems this isn't the case. I'm trying to use this method for animating a date counter on a historical video and it's important the date, lines up exactly with what's happening on the video. And constantly moving keyframes up and down will take a long time. Is there any other solution, or am I missing something.
  
  **Tags:** after-effects
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-04-14. Score: 0
  
  The value of the text will recalculate on every frame, based on the value of your slider at that time, so if you've set the following values:
  
  ```
  frame = 1  slider = 1
  frame = 20 slider = 2
  
  ```
  
  then the value of the slider at frame 10 will be 1.5
  
  On frame 19 it will be 1.95 as that is the correct linear calculation of that value at that time.
  
  It might be easier if you make a new answer explaining exactly what you want to achieve.
  
  If you want only a single decimal place, you could do that like this:
  
  ```
  slider = (effect("Slider Control")("Slider").value);
  output = (Math.round(slider * 10))/10;
  SourceText = output
  
  ```
  
  The Math.round function (note the annoying capital 'M'), causes the number to round to the nearest whole number. Because you want decimal places, we multiply it up by ten inside the function, do the rounding, then divide it again after the rounding. Think of the number of zeroes in that line as the number of decimal places you want, ie if you wanted two decimal places, change the '10' values both to '100'.
  
  This will give you:
  
  ```
  Frame = 1  text = 1.0
  Frame = 10 text = 1.5
  Frame = 19 text = 1.9
  Frame = 20 text = 2.0
  
  ```
  
  If you wanted to keep the value rounded down until you hit frame 20, use Math.floor like this:
  
  ```
  slider = (effect("Slider Control")("Slider").value);
  output = (Math.floor(slider));
  SourceText = output
  
  ```
  
  Which gives:
  
  ```
  Frame = 1  text = 1
  Frame = 10 text = 1
  Frame = 19 text = 1
  Frame = 20 text = 2
  
  ```
  
  Or if you wanted to keep it rounded down to one decimal place:
  
  ```
  slider = (effect("Slider Control")("Slider").value);
  output = (Math.floor(slider *10))/10;
  SourceText = output
  
  ```
  
  Gives:
  
  ```
  Frame = 1  text = 1.0
  Frame = 10 text = 1.5
  Frame = 19 text = 1.9
  Frame = 20 text = 2.0
  
  ```
  
  You can also use the Toggle Hold function in your keyframes by right clicking a keyframe, and selecting 'Toggle Hold', which will hold your slider at a specific value if you need to.
  
  In general, every time I'm working with sliders for text expressions, I start with this expression:
  
  ```
  slider = (effect("Slider Control")("Slider").value);
  tidying = (Math.round(slider * 100))/100;
  SourceText = "$" + tidying + "bn" +"\r" +"DEBTS";
  
  ```
  
  Which usually gets me close to what I need - it allows for rounding to two decimal places (the 100 values do this), text before the value (in this case a dollar sign), text after the value ("bn"), and a new line (created using "\r"), and text on the line beneath it ("DEBTS").
  
  I think there are neater ways to do this now - take a look at [these rounding techniques](https://ukramedia.com/4-different-ways-to-round-numbers-in-after-effects/), but this is the way I usually do it.
  
  > **Comments:**
  > **username_0**: This answers and explains it beautifully thank you. In the end I ended up adding one decimal point so that the number wouldn't round up prematurely. And to hide the decimal I just used a mask. My problem in this case is that my video is about a historical event and in my animation, I need the date to turn from 1520 to 1521 at an exact point in the animation. So when I put the keyframe in the exact location the number changes too early. Unfortunately the 'Numbers' effect doesn't help me because I can't set it back in time earlier than 1910. I'm gonna look into the things you sent.  
  > **username_1**: use two hold keyframes on the two frames where you need them to switch - ie one at 1520, and one at 1521  
  
  ---
  
  