Activity › Forums › Adobe After Effects Expressions › Math.round a Slider number
-
Math.round a Slider number
Posted by Eden Exposito on November 5, 2008 at 3:09 pmHi!
I want see a value of one slider, but rounded.
I writte this expression in source text of one layer text:
thisComp.layer(“layer”).effect(“Sliderlayer”)(“slider”).toFixed(Math.round(1));
And i have an error… i think that “thisComp.layer(“layer”).effect(“Sliderlayer”)(“slider”)” is not a math number maybe i need convert to it before make a Math.round… how i can get value of slider and round it, to print on screen?Thanks!!
Billy Mitchell replied 7 years, 11 months ago 7 Members · 10 Replies -
10 Replies
-
Kevin Camp
November 5, 2008 at 5:14 pmyou’re close…
the value that you want to be affected by the math function (in this case rounded) needs to be within the the ()… so it should look like this:
Math.round(thisComp.layer(“layer”).effect(“Sliderlayer”)(“slider”))
essentially, your saying ’round(this number)’…
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Eden Exposito
November 5, 2008 at 7:23 pmBut if i want 1 or 2 decimal precision like 83,45?
How i can writte the expression?
Thanks! -
Kevin Camp
November 5, 2008 at 8:01 pmyou could use a multiplier prior to the rounding, then divide by the multiplier to get the decimal back…
some like this:
n = thisComp.layer(“layer”).effect(“Slider Control”)(“Slider”);
d = 100; // set your decimal places: 10ths, 100ths, 1000ths, etc.
Math.round(n*d)/dKevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Dan Ebberts
November 5, 2008 at 8:29 pmI think all you need is something like this:
thisComp.layer(“layer”).effect(“Sliderlayer”)(“Slider”).value.toFixed(2,10)
Dan
-
Kevin Camp
November 5, 2008 at 8:43 pmthat’s cool, what’s the 10 define in toFixed(2,10)?
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Dan Ebberts
November 5, 2008 at 8:57 pmOoops. Good catch. That shouldn’t be in there. I was thinking of something else (not sure what though).
Dan
-
Espen Jakobsen
March 9, 2011 at 12:53 pmAh, thank you so much! Just saved my ass on a tight deadline! 🙂 Cant believe it was that simple to round numbers.
Espen Jakobsen
Multimedia Designer
https://massiverhino.no/
https://www.espenja.com/ -
Jeremy Krzmarzick
May 1, 2017 at 3:57 pmI just came across this problem today, so almost 10 years later this is still a problem! I fixed it by doing something sort of like what was suggested but putting the my keyframes in I believe would be called the “argument” of the expression aka Math.round( ‘Pick wipe the animated effect perimeter’)
Math.round(effect("3D Stroke")("End")) -
Billy Mitchell
June 12, 2018 at 3:37 pmFor two decimal places:
A neat little math trick, multiply and then divide by 100.
Math.round(effect("Slider Control")("Slider")*100)/100
Reply to this Discussion! Login or Sign Up