• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to limit the number of decimals a Slider shows

Community Beginner ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

Hi all!

 

I'm currently working on a timer in AE — it will be used for SAT tests, so I have to make sure that it keeps perfect time. Here's the code I've used to create it:

 

slider=effect("Slider Control")("Slider");
sec=slider%60;
min=Math.floor(slider/60);

function addZero(X){
if(X<10)return"0"+X else return X;
}
addZero(min)+":"+addZero(sec)

 

While this function does keep perfect time, it displays all the decimals in between each whole second (00:00.96666666...). Is there a code I can insert that limits the displayed decimals to just the minutes and seconds, and doesn't round up the numbers? (I've found using    slider = Math.round(effect("Slider Control")("Slider"));    rounds the time up and displays the seconds before they should. EX: 00:02 shows up at 00:01:15 instead of 00:02:00)

 

Any and all help is greatly appreciated.
Thanks, have a great day!
— Joshua L

TOPICS
Expressions , How to , Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Nov 08, 2019 Nov 08, 2019

OK:

 

slider=effect("Slider Control")("Slider");
sec=Math.floor(slider%60);
min=Math.floor(slider/60);

function addZero(X){
if(X<10){
return"0"+X
}else{
return X
}
}
addZero(min)+":"+addZero(sec)

Votes

Translate

Translate
Advisor ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

Would replacing your second line with this help:

sec=Math.floor(slider%60);

 

But - wouldn't it be easier just to use the built in expression 'time' function to do this job? Or do you need the flexibility of this keyframeable approach?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

That did the trick!! Thank you so much Mike!

 

I've actually never used that function before. Admittedly, I'm a bit new to After Effects. How does that work?

Or would you happen to have a link to a tutorial that explains how that works?

 

Thanks again, have a great day!
— Joshua L

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

Just type : time

into the expression field of a text source property. Then hit the spacebar. It will output the 'current time' in seconds : )

 

PS: If you can hit 'correct answer' on my first reply that will mark this thread as answered.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

How that sounds really helpful actually. Thanks for taking the time to explain!

 

Will do!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

That Expression will not work with AE's Javascript engine - it will throw up an error. Where did you get this script?

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

OK:

 

slider=effect("Slider Control")("Slider");
sec=Math.floor(slider%60);
min=Math.floor(slider/60);

function addZero(X){
if(X<10){
return"0"+X
}else{
return X
}
}
addZero(min)+":"+addZero(sec)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

I strongly approve your OK. 🙂

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

LATEST

: )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines