Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Countdown timer dont show decimals

  • Countdown timer dont show decimals

    Posted by René Kubovič on July 17, 2023 at 1:24 pm

    Hello guys,

    im very desperate with Countdown timer im working on

    Aim is to create timer that goes from 90 minutes in format 90:00 to 00:00

    itried many ways how to do it (im not so skilled in expressions) right now the expression for minutes is (its cuz client wants “0” zeroes before number when its 09:00 or else minutes left.

    without it worked just fine, but now with this it rounding up the “minutes number”

    EG: when its 9:45 – shows as 10:45 because its 9,75 rounded up to 10… 9:29 it jumps to right minute mark, but then again on 8:59-8:30 it shows with 9. If i turn of rounding, its showing crazy numbers with x decimal numbers behind comma.

    How to fix it to make it work please?

    Or maybe if there is other workaround how to format regular timer that wouldnt show hours just minutes?

    Thank you good people for every help!

    nums = ((-time+thisComp.layer("Settings").effect("Seconds")("Slider"))/60)+thisComp.layer("controls").effect("pocet-minut")("Slider");

    amtOfZeroes = 2;

    isNeg = false;

    if(nums < 0) { nums = Math.abs( nums ); isNeg = true; } sVal = nums.toFixed(0) + ""; while(sVal.length < amtOfZeroes) { sVal = "0" + sVal; } if(isNeg) sVal = "-" + sVal; sVal

    Brie Clayton replied 3 years ago 3 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    July 18, 2023 at 8:14 am

    Hello René,

    since you may be dealing with negative numbers, I would use Math.trunc()for the minutes instead of the more common floor().

    nums = ((-time+thisComp.layer("Settings").effect("Seconds")("Slider"))/60)+thisComp.layer("controls").effect("pocet-minut")("Slider");
    mins = Math.abs(Math.trunc(nums));
    secs = Math.abs(Math.floor(60*nums%60));
    (Math.sign(nums)==-1 ? "-":"") + mins.toString().padStart(2,"0") +":" + secs.toString().padStart(2,"0");

    if you get an error that .trunc() and .sign() aren’t defined, you have to set the Expressions engine of the project-settings to”Javascript”.

    (Edit: I changed a few things to get less floating point rounding errors, so the seconds change more consistently on the same frame)

  • René Kubovič

    July 18, 2023 at 11:34 am

    Thank you so much good sir!
    You saved me

  • Brie Clayton

    July 18, 2023 at 4:36 pm

    Thank you for the solve, Filip!

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