Creative Communities of the World Forums

The peer to peer support community for media production professionals.

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

    Billy Mitchell replied 7 years, 11 months ago 7 Members · 10 Replies
  • 10 Replies
  • Kevin Camp

    November 5, 2008 at 5:14 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

  • Eden Exposito

    November 5, 2008 at 7:23 pm

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

  • Dan Ebberts

    November 5, 2008 at 8:29 pm

    I 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 pm

    that’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 pm

    Ooops. 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 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
    https://massiverhino.no/
    https://www.espenja.com/

  • Mikołaj Mikucki

    August 10, 2015 at 3:23 pm

    hah works for me though

  • Jeremy Krzmarzick

    May 1, 2017 at 3:57 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"))

  • Billy Mitchell

    June 12, 2018 at 3:37 pm

    For two decimal places:

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

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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy