Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Remove decimals

  • Posted by Paul Roper on June 17, 2013 at 2:59 pm

    Hello,
    I’ve been trying to simply remove the decimals from a number; eg. I want 9.9 rounded to 9, just killing off everything after the decimal point. So Math.round and toFixed don’t work; they do it “mathematically properly”. I’m trying to divide one number by another, but only want a whole integer result.

    I remember from the dim and distant past that BBC Basic (from the 1980s!) had a DIV function, that gave “the integer quotient of two items. The result is always an integer”, so 21 DIV 5 would give 4. I assume Javascript must have some equivalent of this? I suppose I could do a workaround and subtract the remainder from the first number:

    a=21;
    b=4
    c=a%b;
    (a-c)/b

    …but that’s a bit of a palaver!

    Any other suggestions, please?

    Thanks,

    Paul

    Paul Roper replied 12 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Paul Roper

    June 17, 2013 at 3:17 pm

    Aha! After some searching around the world of Javascript, I found the rather bizarre:

    ~~

    …so:

    n=16.99;
    ~~n

    wound give the desired:

    16

    – Paul.

  • Dan Ebberts

    June 17, 2013 at 4:29 pm

    How about Math.floor()?

    Dan

  • Paul Roper

    June 20, 2013 at 1:20 pm

    Thanks Dan!

    Incredibly, a Google search for ~~ returns no results. But I managed to find out that ~~ (a double bitwise NOT, apparently) and Math.floor perform the same thing.

    – Paul

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