Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Keep First Decimal Zero in Counter

  • Keep First Decimal Zero in Counter

    Posted by Steve Brown on October 9, 2014 at 8:43 pm

    Hi Guys,

    I’m working on a bar chart that calculates the % of change between two values in the chart. Everything works fine except whenever the tenths place = 0, it disappears. For example, 2.0 becomes 2

    I’d like to keep that zero. Here’s the expression as I have it written so far; it’s in the “Source Text” parameter of a text layer.

    var valueA = thisComp.layer( index + 5 ).effect(“Value Control”)(“Slider”);
    var valueB = thisComp.layer( index + 3 ).effect(“Value Control”)(“Slider”);
    var valueDifference = (valueB – valueA);
    var divideChange = clamp(valueDifference / valueB, -9.99, 9.99)

    if (valueDifference < 0) {
    displayValue = Math.round(divideChange*1000) / 10 + “%”
    } else {
    displayValue = “+” + (Math.round(divideChange*1000) / 10 + “%”)
    }
    displayValue

    Dan Ebberts
    replied 11 years, 7 months ago
    2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    October 9, 2014 at 9:27 pm

    Instead of doing this:

    Math.round(divideChange*1000) / 10 + “%”

    I’d do it this way:

    (divideChange*100).toFixed(1) + “%”

    Dan

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