Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Decimal Numbers ( remove .0 )

  • Decimal Numbers ( remove .0 )

    Posted by Nick Kennedy on October 23, 2019 at 1:31 pm

    Is it possible for an expression to recognise when a number (provided by an expression slider) has a zero as decimal (i.e. 2.0) and then remove the decimal point and zero (i.e. 2 ) but keep them if the number is 2.5 (for example). I kind of think it would need an If/else statement but I’m not sure how to make it recognise .0 if this is possible at all?
    Any help would be greatly appreciated (and save me pulling out all my hair) thanks,

    Nick Kennedy replied 6 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 23, 2019 at 4:43 pm

    There are probably simpler ways, but this should work:

    n = effect(“Slider Control”)(“Slider”).value.toFixed(1);
    n[n.length-1] == “0” ? n.substr(0,n.length-2) : n

    Dan

  • Nick Kennedy

    October 24, 2019 at 8:52 am

    Hi Dan,

    Thanks for the quick reply. This works great even when I added this

    n = effect(“Slider Control”)(“Slider”).value.toFixed(1);
    n[n.length-1] == “0” ? n.substr(0,n.length-2) : n.replace(“.” , “,”)

    I work in Germany so the decimal point is actually a comma. I then wanted to add a percentage sign (%) to this and I got stuck again. Simply adding +”%” messed up the comma and the removal of the zero decimal. I tried

    n = effect(“Slider Control”)(“Slider”).value.toFixed(1).replace(“.” , “,”);
    n[n.length-1] == “0” ? n.substr(0,n.length-2) : n +”%”

    which works well untill there is a decimal zero but the decimal zero and the % dissappear

    Any Ideas? I’m sure I’m overlooking something simple.

    This is actually one of several improvements I’m making on a german election after effects project which you helped me out with a couple of years ago! Back then after recieving so much help from the creative cloud forums I offered the project to anyone who wanted it and a couple of people got in touch, so I sent it to them. If I manage to get this sorted out again, anyone who needs an “election rig” can get in touch and I’ll send it out.
    Thanks again for your help

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