ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Math.round a Slider number

FAQ   •   VIEW ALL
 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!!

 Re: Math.round a Slider numberon 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"))

Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW

 Re: Math.round a Slider numberon 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!

 Re: Math.round a Slider numberon 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

 Re: Math.round a Slider numberon 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 ```

 Re: Math.round a Slider numberon 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/

 Re: Math.round a Slider numberon 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

 Re: Math.round a Slider numberon 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

 Re: Math.round a Slider numberon 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

 Re: Math.round a Slider numberon Aug 10, 2015 at 3:23:21 pm

hah works for me though

`Math.round(effect("3D Stroke")("End"))`