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 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;
Enjoying this tutorial? Sign up now for the Creative COW Newsletter!
Sign up for the Creative COW newsletter and get weekly updates on industry news, forum highlights, inspirational tutorials, tips, burning questions, and more! Receive bulletins from the largest, longest-running community dedicated to supporting professionals working in film, video, and audio.
Enter your email address, a first and last name, and let us know what you’d like to see more of in the message!