ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Decimal Numbers ( remove .0 )

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nick Kennedy
Decimal Numbers ( remove .0 )
on Oct 23, 2019 at 1:31:46 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,


Return to posts index

Dan Ebberts
Re: Decimal Numbers ( remove .0 )
on Oct 23, 2019 at 4:43:22 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



Return to posts index

Nick Kennedy
Re: Decimal Numbers ( remove .0 )
on Oct 24, 2019 at 8:52:55 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]