• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit
• How to control decimal point when slider control d...

# How to control decimal point when slider control doesnot work

Engaged ,
Nov 21, 2023 Nov 21, 2023

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.

TOPICS
Expressions

Views

203

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 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)+'%'``````

6 Replies 6
Community Expert ,
Nov 21, 2023 Nov 21, 2023

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 + "%";``````

Report

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

Copied

LATEST

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

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

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) + "%";``````

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%

Report

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

Copied

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

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)+'%'``````

Report

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

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.