ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Math.round a Slider number

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eden Exposito
Math.round a Slider number
on Nov 5, 2008 at 3:09:38 pm

Hi!

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!!


Return to posts index

Kevin Camp
Re: Math.round a Slider number
on Nov 5, 2008 at 5:14:12 pm

you'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


Return to posts index

Eden Exposito
Re: Math.round a Slider number
on Nov 5, 2008 at 7:23:38 pm

But if i want 1 or 2 decimal precision like 83,45?
How i can writte the expression?
Thanks!



Return to posts index


Kevin Camp
Re: Math.round a Slider number
on Nov 5, 2008 at 8:01:06 pm

you 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)/d


Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

Billy Mitchell
Re: Math.round a Slider number
on Jun 12, 2018 at 3:37:41 pm

For two decimal places:

A neat little math trick, multiply and then divide by 100.

Math.round(effect("Slider Control")("Slider")*100)/100


Return to posts index

Espen Jakobsen
Re: Math.round a Slider number
on Mar 9, 2011 at 12:53:19 pm

Ah, 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
http://massiverhino.no/
http://www.espenja.com/


Return to posts index


Dan Ebberts
Re: Math.round a Slider number
on Nov 5, 2008 at 8:29:55 pm

I think all you need is something like this:

thisComp.layer("layer").effect("Sliderlayer")("Slider").value.toFixed(2,10)


Dan



Return to posts index

Kevin Camp
Re: Math.round a Slider number
on Nov 5, 2008 at 8:43:09 pm

that's cool, what's the 10 define in toFixed(2,10)?

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW


Return to posts index

Dan Ebberts
Re: Math.round a Slider number
on Nov 5, 2008 at 8:57:52 pm

Ooops. Good catch. That shouldn't be in there. I was thinking of something else (not sure what though).

Dan



Return to posts index


Mikołaj Mikucki
Re: Math.round a Slider number
on Aug 10, 2015 at 3:23:21 pm

hah works for me though


Return to posts index

Jeremy Krzmarzick
Re: Math.round a Slider number
on May 1, 2017 at 3:57:15 pm

I 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"))


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]