Add $ and Comma at thousandth place Expression

//ADD A “$” AND “,” AT THE THOUSANDS PLACE ONLY:
//ADD SLIDER CONTROL TO TEXT
var stringSlider="$"+Math.round(effect("Value")("Slider").value);
if (stringSlider.length > 3){
stringSlider.substr(0, stringSlider.length -3) + "," + stringSlider.substr(-3);
} else {
stringSlider
}

This After Effects expression is designed to add a dollar sign ($) and a comma (,) at the thousands place in a numerical value, specifically for a text layer. Let’s break down how it works:

  1. Slider Control Setup:
    • This expression assumes that you’ve added a Slider Control effect to a text layer. The Slider Control allows you to adjust a numerical value interactively.
  2. Expression Explanation:
    • var stringSlider="$"+Math.round(effect("Value")("Slider").value);:
      • This line creates a variable called stringSlider and assigns it the value of the Slider Control, rounded to the nearest whole number, prefixed with a dollar sign ($).
    • if (stringSlider.length > 3){ stringSlider.substr(0, stringSlider.length -3) + "," + stringSlider.substr(-3); } else { stringSlider }:
      • This conditional statement checks if the length of the stringSlider is greater than 3 (meaning it’s a number with more than three digits).
      • If it is, it uses the substr() function to insert a comma (,) at the third position from the right, effectively adding the comma at the thousands place.
      • If the number has less than four digits, it returns the original stringSlider without any modification.
  3. Output:
    • The result of the expression is a string with a dollar sign ($) followed by the numerical value, with a comma (,) added at the thousands place if applicable.

In summary, this expression allows you to format a numerical value on a text layer by adding a dollar sign ($) and a comma (,) at the thousands place, making it easier to read large numbers. Adjustments to the formatting can be made by modifying the Slider Control and adjusting the expression accordingly.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *