Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Parsing numeric result as a string

  • Parsing numeric result as a string

    Posted by Jared Flynn on March 31, 2010 at 3:35 pm

    Hey all,

    This is probably a very easy fix– I’m working on creating a video overlay to make some footage look like it’s being viewed through a high-tech rangefinder with a compass. To add some extra pizazz I want to send the Rotation value of my compass layer to a text layer nearby, and after the actual number I wanted to add a degree symbol (°). So, the end result of my text layer would look something like this:

    -1.274°

    So I have two questions about getting this piece working. Firstly, the numeric result of just pickwhipping the compass’ Rotation value has WAY too many significant digits (14 decimal places!) and I’d like to come up with a way to have it round to the nearest thousandth of a degree. That’s probably just a Javascript thing that I’m not aware of just yet.

    Secondly, I can’t seem to get the degree symbol tacked onto the end of my text layer’s value. I’ve posted the code I’m using below. I’ve tried other examples of mixing numbers and text in expressions without issue, but something seems to be wrong with what I’ve done here. When I use the code below, AE returns this error:

    After Effects warning: invalid numeric result (divide by zero?)
    Expression disabled.

    Error occurred at line 3.
    Comp: ‘HUDforForm’
    Layer: 2 (‘Bearing’)
    Property: ‘Source Text’

    Is there a tried-and-true way to force AE to parse a numeric value as a string?

    Thanks so much in advance!

    Jared Flynn
    Motion Graphics Designer / Lead AE
    Lone Wolf Documentary Group

    bearingVal = comp("Compass").layer("Modern_nautical_compass_rose_2000px.png").transform.rotation;

    bearingString = bearingVal + "°";

    bearingString;

    Jared Flynn
    Motion Graphics Designer / Lead AE
    Lone Wolf Documentary Group

    Jared Flynn replied 16 years, 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • Jared Flynn

    March 31, 2010 at 4:33 pm

    Quick update: some deeper Googling solved the significant digits issue. See code below!

    Still no luck on adding that degree symbol in though, so any help there would still be greatly appreciated. Thanks!

    Jared Flynn
    Motion Graphics Designer / Lead AE
    Lone Wolf Documentary Group

    bearingVal = comp("Compass").layer("Modern_nautical_compass_rose_2000px.png").transform.rotation;

    bearingRounded = Math.round(bearingVal*1000)/1000; //Rounds result to nearest thousandth

    bearingRounded;

    Jared Flynn
    Motion Graphics Designer / Lead AE
    Lone Wolf Documentary Group

  • Dan Ebberts

    March 31, 2010 at 4:34 pm

    Try this:

    bearingString = bearingVal.toFixed(3) + String.fromCharCode(176);

    Dan

  • Jared Flynn

    March 31, 2010 at 7:12 pm

    Hi there Dan,

    That did the trick! I definitely need to brush up on my Javascript– there’s an awful lot of functionality out there beyond AE’s own expressions. Thanks a million!

    -Jared

    Jared Flynn
    Motion Graphics Designer / Lead AE
    Lone Wolf Documentary Group

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