Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding commas using a slider

  • Adding commas using a slider

    Posted by Tepi Kuncoro on February 4, 2025 at 3:42 pm

    Hello, I need help adding commas using a slider.

    Here is an example:

    t = 123456 (This is the number counter using the slider)
    c = Slider value for adding commas.

    If c = 1, the output should be 12345,6.
    If c = 2, the output should be 1234,56.
    If c = 3, the output should be 123,456,
    and so on…

    Is there anyone who can help or perhaps suggest a more efficient solution?

    Brie Clayton
    replied 1 week, 6 days ago
    3 Members · 3 Replies
  • 3 Replies
  • Yoan Boisjoli

    February 4, 2025 at 3:53 pm

    Hi Tepi!

    Something like that should work:

    t = Math.abs(Math.round(effect("Number")("Slider"))); // Get the number value
    c = Math.abs(Math.round(effect("Comma Position")("Slider"))); // Get the comma position
    tStr = t.toString(); // Convert to string
    len = tStr.length;
    if (c >= len) {
    result = tStr; // If c is larger than number length, return the number as is
    } else {
    insertPos = len - c; // Determine where to insert the comma
    result = tStr.substring(0, insertPos) + "," + tStr.substring(insertPos);
    }
    result;

    This expression takes a number from a slider, converts it to a string, and inserts a comma at the position determined by another slider, counting from the right.

    Cheers!

  • Tepi Kuncoro

    February 4, 2025 at 4:12 pm

    Thank you so much Yoan, for the quick response. It works perfectly!

  • Brie Clayton

    February 4, 2025 at 7:09 pm

    Thank you for solving this, Yoan!

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