FORUMS TUTORIALS MAGAZINE STOCKYARD VIDEOS PODCASTS EVENTS SERVICES NEWSLETTER NEWS BLOGS
 ADOBE AFTER EFFECTS: Home Forum Basics Expressions Tutorials Podcasts AE Techniques Training Creative Cloud Debate FAQ

# whole number slider

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
 whole number slider by ben wolfinsohn on Nov 1, 2012 at 6:58:57 am

I am new to expressions and sliders - is it possible to create a slider that only works with whole numbers, no decimals?

 Re: whole number sliderby Jamie Bradshaw on Nov 1, 2012 at 1:32:52 pm

copy the following expression into your Slider:

Math.floor(value);

Math.floor rounds down whatever number is inside the bracket.

I hope this helps.

JimJamâ€¢Graphics
http://www.jimjamgraphics.com/

 Re: whole number sliderby Darby Edelen on Nov 1, 2012 at 3:14:10 pm

Math.floor rounds down whatever number is inside the bracket."

There's also:

`Math.round()`

Rounds to the nearest number, Math.round(0.5) returns 1, Math.round(0.4) returns 0 for example

`Math.ceil()`

Returns next highest whole number, Math.ceil(0.0001) returns 1 for example

And to complete the picture:

`Math.floor()`

Returns next lowest whole number, Math.floor(1.9) returns 1 for example

Darby Edelen

 Re: whole number sliderby ben wolfinsohn on Nov 1, 2012 at 4:29:08 pm

sorry, this is the first slider and expression i've ever made, where do i paste that exactly?
thanks!

 Re: whole number sliderby Darby Edelen on Nov 1, 2012 at 5:36:31 pm

[ben wolfinsohn] "sorry, this is the first slider and expression i've ever made, where do i paste that exactly?
thanks!"

That depends. If you just want to take the slider value and round it then your entire expression (applied to the slider property) might look like this:

`Math.round(value);`

You could use floor() or ceil() alternatively.

Darby Edelen

 Re: whole number sliderby ben wolfinsohn on Nov 12, 2012 at 11:02:00 pm

I'm still seeing the decimal point in the slider bar. is there no way to remove that then?

 Re: whole number sliderby Dan Ebberts on Nov 13, 2012 at 12:32:40 am

If you're using a text layer, you could use a source text expression like this:

s = effect("Slider Control")("Slider").value;
s.toFixed(0)

Dan

 Re: whole number sliderby ben wolfinsohn on Nov 13, 2012 at 1:04:00 am

sorry, i'm a bit confused. let me try to explain.

I have 3 comps, each comp is time remaped, each remap has an expression like this -

and all 3 of the comps are pointing to the same slider.

so where would i put the code you're talking about? and would I put it in all 3 comps?

 Re: whole number sliderby Dan Ebberts on Nov 13, 2012 at 1:58:27 am

Now I'm confused. If you're not displaying the value, why do you care about the decimal point?

Is it that you have the rounding expression applied to the slider, but when you divide that value by 23.976 you don't get a whole number? How about something like this instead:

Dan

 Re: whole number sliderby ben wolfinsohn on Nov 13, 2012 at 2:44:10 am

that didn't seem to do it.

basically i have a comp with 18 frames, each frame has a drawing of a different perspective of a head. with the slider i can easily scroll through the different faces when i use it with timeremaping. the slider goes from 0-17. BUT, I don't need the slider to display 1.3 for an example, cuz i don't have .3 of a frame. i only need it to show numbers 0-17 in the slider bar.

does that make sense? is it possible?

 Re: whole number sliderby Dan Ebberts on Nov 13, 2012 at 3:22:37 am

If you put the Math.floor(value) expression on the slider, you'll get 0.00, 1.00, etc., but I don't think there's any way to get rid of the ".00" part, if that's what you're asking.

Dan

 Re: whole number sliderby Dan Ebberts on Nov 13, 2012 at 3:30:38 am

Which number are you concerned about, the slider value or the time remapping value? I'm wondering if maybe you expected the time remapping value to be in frames instead of seconds.

Dan

 Re: whole number sliderby ben wolfinsohn on Nov 13, 2012 at 4:24:07 am

just wanted the slider value to be, but I guess I can just ignore the the decimal place, and just look at the whole number and it works fine. 2.01 or 2.93 gives me the same results. so i'll just ignore the other to digits and all is good.