Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Math.round: show always a number of 2 digits

  • Math.round: show always a number of 2 digits

    Posted by Davide Mitidieri on November 7, 2016 at 10:12 pm

    Hi,
    I’m using the expression

    Math.round(effect(("Slider Control")("Slider")))
    in the source of a text layer, which contains a slider. I need to show always 2 digits of the integer number in the slider; for example, “5” sould be shown as “05”, while “10” should be shown as “10”.

    How can I modify the expression in order to do this?

    Thanks in advice.

    Stephen Dixon replied 9 years, 6 months ago 3 Members · 3 Replies
  • 3 Replies
  • Cassius Marques

    November 8, 2016 at 11:50 am

    x=Math.round(effect("Slider Control")("Slider")).toFixed(0);
    while (x.length < 2) x = "0" + x; x

    It adds a 0 if the length of the string is smaller than 2, otherwise its just the number.

    Cassius Marques
    http://www.zapfilmes.com

  • Davide Mitidieri

    November 8, 2016 at 8:23 pm

    Ok it works, thanks a lot!

    However, what if I’m working with a string made of 2 numbers, separated by “:”? (I’m making a chronometer)

    I’ve tried to edit your expression, but it seems a bit harder, and I’m not used to work with After Effects expressions.

    Thanks in advice

  • Stephen Dixon

    November 9, 2016 at 1:37 am

    use Cassius’s expression for each group of numbers, and then join them together by simply adding them. So say you have two sliders, one for seconds and one for minutes (is that what you’re doing?):

    sec = Math.round(effect("Slider Control")("Slider")).toFixed(0);
    while (sec.length < 2) sec = "0" + sec;
    min= Math.round(effect("Slider Control")("Slider 2")).toFixed(0);
    while (min.length < 2) min = "0" + min;
    min + ":" + sec

    Stephen Dixon
    Editor, Animator, Motionographer
    Museum Victoria

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