0

Thought this would be simple but doesn't seem so. How can I remove all numbers after the decimal point in an expression, or round down to 0 decimal places (which is the same result)

For instance I have an integer: 2903.99302 I want to remove everything after decimal place, so that it results in 2903

Can't find how to do this. Some ideas:

num = 2903.99302;
dec = num.search(".");  // OR dec = num.find(".");

result = num.substr(0, dec);

or

num = 2903.99302;
result = num.rounddown(0);

or

num = 2903.99302;
result = num.toFixed(0);

Apparently AE can also use JavaScript in recent versions. I'm on version 2021 and it's not basic javascript functions aren't recognised so not sure if there's some weird syntax...

1 Answer 1

1

Normally I would use Math.round like this when trying to display text:

slider = (effect("Slider Control")("Slider").value);
tidying = (Math.round(slider * 100))/100;
SourceText = "$" + tidying + "bn" +"\r" +"DEBTS";

the .value is sometimes needed to force AE to look at the slider as a number, not as an object.

tidying is being done to round (up) to 2 decimal places \r gives a line break

text is appended with +”text”+

If you want to round down, you can use

Math.floor()

instead

1
  • I came up with this hacky way to round down but it's not as clean as Math.floor() so replaced - thanks! num= 2903.99302; fix= num.toFixed(0); len= fix.length; str= num.toString(); new = str.substr(0,len); result= parseInt(new);
    – 5Diraptor
    Jan 31 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.