Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions creating even numbers

  • creating even numbers

    Posted by Kevin Camp on October 11, 2007 at 8:16 pm

    is there a better way to restrict values to even numbers than this:

    Math.round((value / 2) + 0.49) * 2;

    i’m dividing a value by 2 adding a fraction, rounding that and then multiplying the result by 2… it just seems like there should be an easier way…

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

    Kevin Camp replied 18 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    October 11, 2007 at 8:57 pm

    Not much simpler:

    Math.round(value/2)*2

    Or, if you don’t want it to change to 2 until it value gets to 2:

    Math.floor(value/2)*2

    Dan

  • Kevin Camp

    October 11, 2007 at 9:08 pm

    thanks dan,

    i just figured out how i might manipulate the % function (what’s % called anyway.. remainder?):

    value + (value%2)

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

  • Dan Ebberts

    October 11, 2007 at 11:01 pm

    % is called the modulus operator.

    Dan

  • Kevin Camp

    October 11, 2007 at 11:23 pm

    thanks again

    Kevin Camp
    Designer – KCPQ, KMYQ & KRCW

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