Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Extra decimal places using math.floor expression

  • Extra decimal places using math.floor expression

    Posted by Matt Robinson on January 3, 2012 at 7:59 pm

    Hey everyone, I’ve got an expression that I am using which converts a degree of rotation (0-180) into a percentage of blood alcohol content (.01-.40). I’ve got everything functionally working, my only problem is that when it reaches a whole number – .3 – I’m losing the ‘0’ that I want to display after the ‘3’ – making it .30. Is there any modification I can make that will allow that extra 0 to display – even though mathematically it’s irrelevant? My expression is below.

    The value that the math.floor part is modifying is the degree of rotation of a needle on a gauge – any value between 0 degrees and 180 degrees. I may have overcomplicated the whole expression but any advice is greatly appreciated. Thanks!

    (Math.floor(((thisComp.layer("needle wiggle").transform.rotation)/4.5)))*.01

    David Cabestany replied 12 years, 9 months ago 4 Members · 8 Replies
  • 8 Replies
  • Juan Bosnic

    January 3, 2012 at 9:24 pm

    Let ME talk about overcomplicating stuff…

    Take a look at the expression below. It converts the rotation value, makes it a String, and evaluates if it has just one character to add a “0” accordingly.

    That should help while somebody smarter thinks something simpler.

    needleRot = Math.floor((thisComp.layer("needle wiggle").transform.rotation)/4.5) * 0.1
    needleRot = needleRot.toString();

    if (needleRot.length == 1){
    needleRot + ".0";
    } else {
    needleRot;
    }

  • Juan Bosnic

    January 3, 2012 at 9:35 pm

    Ok I screwed it. Wont help at all yet, but it’s a good starting point, I just misunderstood where you wanted the “0” to be.

    Below is the corrected expression.

    needleRot = (Math.floor(((thisComp.layer("needle wiggle").transform.rotation)/4.5)))*.01
    needleRot = needleRot.toString();

    if (needleRot.length == 3){
    needleRot + "0";
    } else {
    needleRot;
    }

  • Dan Ebberts

    January 3, 2012 at 9:37 pm

    This should do it:

    n = (Math.floor(((thisComp.layer(“needle wiggle”).transform.rotation)/4.5)))*.01;
    n.toFixed(2)

    Dan

  • Matt Robinson

    January 3, 2012 at 9:56 pm

    Thanks for the replies guys! I appreciate it. Dan’s expression worked perfectly!

  • David Cabestany

    July 22, 2013 at 4:47 pm

    When I add the n.toFixed portion to my expression I’m getting an error, I tried it on a random expression and it worked fine, but when I change the random expression for one driven by a slider I get the following message: Function n.toFixed is undefined.

    Could anyone help me to correct the expression? I need it to go from 0 to 7.2.

    Thanks.

    n=(effect("Slider Control")("Slider"));
    n.toFixed(2);

  • David Cabestany

    July 22, 2013 at 4:48 pm

    When I add the n.toFixed portion to my expression I’m getting an error, I tried it on a random expression and it worked fine, but when I change the random expression for one driven by a slider I get the following message: Function n.toFixed is undefined.

    Could anyone help me to correct the expression? I need it to go from 0 to 7.32.

    Thanks.

    n=(effect("Slider Control")("Slider"));
    n.toFixed(2);

  • Dan Ebberts

    July 22, 2013 at 5:40 pm

    Try it this way:

    n=(effect(“Slider Control”)(“Slider”)).value;
    n.toFixed(2);

    Dan

  • David Cabestany

    July 23, 2013 at 3:57 am

    Thanks Dan! as usual it worked, also if you remove the n variable it works too, my final expression looks like this:

    Thanks again.

    effect("Slider Control")("Slider").value.toFixed(2);

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