After Effects Tutorial - Expression to Add Zeros Before Counter

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ค. 2024
  • Thanks for viewing! / andyfordvideo
    I’ve been asked many times about adding zeros in front of a number counter so that there are always a select number of digits appearing. A counter like this can be likened to a speedometer. This is done with expressions to pad your string.
    As usual, the initial expression from linking a text layer's source text to a slider control will be:
    num = effect(“Slider Control”)(“Slider”);
    Then, set the length of the string. If you want 6 digits to always show, use the following for another variable:
    x = 6 - num.toString().length;
    Then, one more line of code is needed to return the proper value. Basically, you will return the modified substring plus your original number that is controlled via slider control. The number of zeros in quotes varies depending on the number of digits you wish to return. Sticking with the 6-digit example, use the following:
    “00000”.substr(0,x) + num;
    #adobe #aftereffects #motiongraphics #vfx #expressions

ความคิดเห็น • 4

  • @howardsend6589
    @howardsend6589 2 ปีที่แล้ว +1

    What a simple and useful video. Many thanks.

  • @damienboneham2754
    @damienboneham2754 2 ปีที่แล้ว +2

    Hi - im getting those crazy decimal numbers when I try this. Adding Math.round isn't working for me either, is there something im missing?

  • @mysteriumxarxes3990
    @mysteriumxarxes3990 2 ปีที่แล้ว

    ok, how do I do that with a comma in it, for like lets say I want 1,500. I wanna count it up from 0 with 0 zeros and the ,

  • @howardsend6589
    @howardsend6589 2 ปีที่แล้ว +6

    To get rid of any unwanted decimals, your first code line can be:
    num = effect ("Slide Control")("Slider").value.toFixed();