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

How to control decimal point when slider control doesnot work

Engaged ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Hello,

 

I am learning expressions. so I know that when I want to control decimal point I have to apply slidercontrol and also Math.round().

 

I want to animate a circle and a number, both togeather.  so I applied trim path and whip source text with ''end' of the 'trim path' . I also apply slider control to control decimal point and also apply Math.round()

 

Problem is when I put keframe to animate the trim path the decimal point comes back and I dnt know what I should do to get round figure like solid number.

 

Please guide me.

 

slider.gif

TOPICS
Expressions

Views

344

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

Community Expert , Nov 21, 2023 Nov 21, 2023

Your original expression was pretty close. Try it this way:

n = Math.round(effect("Slider Control")("Slider"));
end = thisComp.layer("circle").content("Trim Paths 1").end.value;
end.toFixed(n)+'%'

Votes

Translate

Translate
Community Expert ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Your first line isn't actually doing anything, it's being skipped. If you only had the first line then it would be executed in the expression. You coudl then add your percent symbol to the end of the slider value.

 

If you, however, do want to display the Trim Paths value, then you need to round that. Using proper variable declaration, good naming conventions, and semicolons after each line,  you can write you code like this:

 

 

const trimPathsEnd = thisComp.layer("circle").content("Trim Paths 1").end.value;
const roundedValue = Math.round(trimPathsEnd);

roundedValue + "%";

 

 

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
Engaged ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

LATEST

You are so right, The slider stopped working. Thank you so much. I ams till learning, I will follow your advice.

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 Expert ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

If you want to control the number of decimal places, add .toFixed() to the expression. You should also avoid using reserved words like "value" "end," or "position" as variables. I would write the expression like this if I wanted the text layer to generate two decimal points:

 

 

v = thisComp.layer("Circle").content("Ellipse 1").content("Trim Paths 1").end.value;
v.toFixed(2) + "%";

 

 

RickGerard_0-1700587619744.gif

You have to declare the value after the end property to get toFixed() to give you a number. I would also add CC Force Motion Blur set to use Native Motion Blur to the text layer to make the rapidly changing numbers a little easier to look at. I would also Right Justify the text layer to keep it from bouncing around as the value decreases from 100.00% to 0.00%

 

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
Engaged ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Thank you so much. I am really greatful, i will follow your advice about writting the code. 

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 Expert ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Your original expression was pretty close. Try it this way:

n = Math.round(effect("Slider Control")("Slider"));
end = thisComp.layer("circle").content("Trim Paths 1").end.value;
end.toFixed(n)+'%'

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
Engaged ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

I do no know enough english to thank you. I am so happy that It worked. You code works perfectly Thank you so much.  

 

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