Copy link to clipboard
Copied
Hi! I have created a counter on a text layer that counts length in increments om 40 cm controlled by a slider, I added this expression to the source text property and it works great except for the decimals.
t = effect("Slider Control")("Slider")
x = Math.round(t/.4)*.4+0.0001
x = x + " Meter"
x.toString().replace(".", ",");
It now counts 0,001 Meter.... 0,4001 Meter... 0,8001 Meter.... 1,2001 Meter..... but i want it to only show 2 decimals: 0,40..0,80..1,20..1,60...
I added the +0.0001 in Math.round to get decimals at the whole numbers. I.e. 4 Meter is now 4,0001 Meter... But how do I remove the last two digits? Or is there another way to always show 2 decimals? I need the counter speed to be controlled over time and masking is a problem since the font I use is not monospaced.
Thank you.
Sorry, I completely missed the increments of 0.40 part. That would change it to:
t = effect("Slider Control")("Slider").value;
x = (Math.round(t/.4)*.4).toFixed(2) + " Meter";
x.toString().replace(".", ",");
Dan
Copy link to clipboard
Copied
Try it this way:
t = effect("Slider Control")("Slider").value;
x = t.toFixed(2) + " Meter";
x.toString().replace(".", ",");
Dan
Copy link to clipboard
Copied
Should i add this somwhere in my expression? If i just use this i only get a "normal counter" I.e. 1,25 Meter...1,26 Meter...1,27 Meter....
I need the counter to count up in increments of + 0.40 meter with two decimal digits. 0,40 Meter... 0,80 Meter....1,20 Meter...1,60 Meter
Copy link to clipboard
Copied
Solution:
I added another "replace string" at the bottom and removed the last "01" in the decimals with empty space. I then created a second text layer and pick whipped the source text to layer 1 source text.
full expression, Layer 1 :
t = effect("Slider Control")("Slider")
x = Math.round(t/.4)*.4+0.0001
x = x + " Meter"
x.toString().replace("01", "");
In Layer 2 i added the:
.toString().replace(".", ",");
string and made this the actual visible counter.
Full expression, Layer 2.
thisComp.layer("Layer1").text.sourceText
.toString().replace(".", ",");
Copy link to clipboard
Copied
Sorry, I completely missed the increments of 0.40 part. That would change it to:
t = effect("Slider Control")("Slider").value;
x = (Math.round(t/.4)*.4).toFixed(2) + " Meter";
x.toString().replace(".", ",");
Dan
Copy link to clipboard
Copied
Thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now