Adding Commas to Animated Numbers CC2019

The expression engine has changed and I’ve been caught out a couple of times now when coming back to reuse the expression I wrote in 2014.

The following expression works with both the Legacy Expression engine and the new JavaScript engine. The fiddly bit is that the format function needs to be defined before it is used (didn’t seem to matter in the older versions).

// Pick-whip number from Slider or Point Control and assign to mySlider
// eg. var mySlider = effect("Point Control")("Point")[0];
// Below the defined format() function, process the slider input
// eg. format(mySlider, "-") or format(mySlider) with default settings

var mySlider = 1234567890;

var format = function(number, separator, groupSize, decimals){
	
	// Set defaults
	groupSize = (groupSize == undefined) ? 3 : groupSize;
	decimals = (decimals == undefined) ? 0 : decimals;
	separator = (separator == undefined) ? "," : separator;

	// Round to given decimal places and convert number to string
	var strNumber = Number(number).toFixed(decimals).toString()

	// Store decimal places separately, with a bullet point if they exist or empty string if not.
	var arrNumber = strNumber.split('.')
	var decimalPlaces = (arrNumber.length > 1) ? '.' + arrNumber[1] : '';

	// Convert to array to split into characters
	var anum = arrNumber[0].split('');

	// New array to hold formatted number
	var fnum = new Array();

	var count = 0;

	// Process the characters in reverse, inserting a comma after each groupSize.
	for(var i = anum.length-1; i >= 0; i--){
		fnum.push(anum[i]);
		count++;
		// If the count is divisble by the groupSize and this is not the last (ie. first) character, add a comma.
		if(count % groupSize == 0 && i != 0){
			fnum.push(separator);
		}
	}
	return fnum.reverse().join('') + decimalPlaces;
}

'$' + format(mySlider, ",")

Ramp to Null expression

grad-1

These expressions will link the Start and End points of the Gradient Ramp effect to the position, rotation and scale of a null layer. Alternatively, you could use the first expression (slightly modified) to link the Start and End points to 2 separate null layers.

Continue reading