Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions removing decimals doesn’t work

  • removing decimals doesn’t work

    Posted by Jacob Danell on July 21, 2013 at 1:47 am

    Hi! I have worked a while now with a script, the only thing left now before it’s 100% done is to fix an error I get when the pixelwidth that gets generated has decimals in it.
    I search around and found that you should add “.toFixed(0)” to remove the decimals but how ever I apply it it doesn’t work. I get an error and the script stops working.

    This is the part of the script:

    var mainWtheP = maincompWidth*thePercentage;
    var mainWm1theP = maincompWidth*(1-thePercentage);
    var mainWthePfixed = mainWtheP.toFixed(0);
    var mainWm1thePfixed = mainWm1theP.toFixed(0);

    alert(mainWthePfixed);

    /*Create two new precomps*/
    var tempComp1 = app.project.items.addComp("tempcomp1", mainWthePfixed, maincompHeight, maincomPA , maincompDur, maincomFR);
    var tempComp2 = app.project.items.addComp("tempcomp2", mainWm1theP.toFixed(0), maincompHeight, maincomPA , maincompDur, maincomFR);

    If I remove the “.toFixed(0);” it works perfect (if it doesn’t become decimals) but even if it doesn’t become decimals and I use “.toFixed(0)” I get the error and the scrip stops =/
    I added “alert(mainWthePfixed);” to see if it changed and the alert shows exactly the numbers I want to go into the variable.

    What should I do? 🙁

    Jacob Danell replied 13 years ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    July 21, 2013 at 3:00 am

    What does the error message say?

  • Jacob Danell

    July 21, 2013 at 11:25 am

    After Effects error: Unable to call “addComp” because of parameter 2. 112 is not an integer.

  • Jacob Danell

    July 21, 2013 at 1:56 pm

    I was searching on google and found this in an other thread
    “With respect to the Position and Anchor Point properties, AE resamples an image when (a)a layer is animated and it is set to Best Quality and (b) a layer is static and the difference between the Anchor Point and Position is not an integer. “
    So maybe the problem lies there? I still have no idea how to solve it =/

  • Xavier Gomez

    July 21, 2013 at 3:34 pm

    toFixed() returns a string, not a number, this is why you get the strange message ‘112 is not a number’.
    You can either do parseInt(mainWtheP.toFixed(0)), or more directly Math.round(mainWtheP).

    Xavier

  • Jacob Danell

    July 22, 2013 at 11:08 am

    Worked perfect. Thank you!

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