Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Modifying Quba Michalskis already awesome überNumber preset

  • Modifying Quba Michalskis already awesome überNumber preset

  • søren kristensen

    February 28, 2021 at 7:08 pm

    the überNumber preset does everything I need when it comes to formatting numbers; lets me set the number of leading digits, number of decimals etc. and maybe most importantly: lets me define which character to use as separator for decimals and thousands. To make it work, you simply change the appropriate values in the expression.

    What I would like to do is to modify it so that all input happens through expression control sliders/checkboxes/dropdown menus, so that my colleagues who know even less about expressions than I do, would be able to use it. I kan link all the parameters that are based on a number, like number of decimals or number of leading digits, to expression control sliders, but I can’t figure out how to link for instance the decimalSymbol parameter to a dropdown menu with set options like “.” and “,”, or simply to the source text of a text layer where you can just type in the symbol you want. Any ideas?

    Here is the preset:

    myUberNumber = uberNumber( -1234.5678 , 5 , 5 , “.” , 3 , “,” , “$” );

    /* UberNumber 1.2 by Quba Michalski

    Articles

    Use:

    uberNumber( number , leadingDigits , decimalDigits , decimalSymbol , digitGrouping , groupingSymbol , leadingSymbol );

    Function arguments:

    number: the number you want to work with. Type it or link a value through expressions

    leadingDigits: number of digits to appear before decimal point. Will not shorten longer numbers, but will add leading zeros if necessary (0 to disable/default)

    decimalDigits: number of digits to appear after decimal point. Will round or add zeros if necessary. (0 to disable/default)

    decimalSymbol: symbol/string to use in place of the decimal point. Requires “” quotation marks. (“” to default to a period)

    digitGrouping: break the digits before decimal point into separated groups (turn 1000000 into 1,000,000). This value defines the length of each group, commonly 3. (0 to disable)

    groupingSymbol: define the symbol used for grouping digits, if active. (“” to default to a coma)

    leadingSymbol: add an additional symbol, such as currency or a hash in front of the number. The symbol will be placed between the “-” negative sign and the number, if negative. (“” to disable)

    If fewer than 7 arguments are provided, the function will assume that ones in the end are missing and use provided arguments in the order they appear

    i.e. uberNumber( 12.34 , 4 , 1 ); will print out 0012.3 – ignoring the remainder of functionalities and only using the first three arguments

    */

    function uberNumber(number,leadingDigits,decimalDigits,decimalSymbol,digitGrouping,groupingSymbol,leadingSymbol){isNeg=false;if(!number){return”N/A”}if(!leadingDigits&&!decimalDigits&&!decimalSymbol&&!digitGrouping&&!groupingSymbol&&!leadingSymbol){return””+number}if(!decimalSymbol){decimalSymbol=”.”}if(!groupingSymbol){groupingSymbol=”,”}if(number<0){isNeg=true;number=Math.abs(number)}if(number==Math.floor(number)){preStr=””+number;postStr=””}preStr=””+Math.floor(number);try{postStr=””+number;postStr=postStr.substr(preStr.length+1)}catch(e){postStr=””+number.value;postStr=postStr.substr(preStr.length+1)}if(!decimalDigits&&decimalDigits!=0){decimalDigits=postStr.length}decimalDigits=Math.round(decimalDigits);if(decimalDigits<1){postStr=””;decimalSymbol=””}else{multiplier=Math.pow(10,decimalDigits);postNum=number-Math.floor(number);postNum=Math.round(postNum*multiplier);postNum/=multiplier;postStr=””+postNum;postStr=postStr.substr(2,decimalDigits);while(postStr.length<decimalDigits){postStr=postStr+”0″}}if(!leadingDigits){leadingDigits=preStr.length}while(preStr.length<leadingDigits){preStr=”0″+preStr}if(!digitGrouping){digitGrouping=0}digitGrouping=Math.round(digitGrouping);if(digitGrouping>0){tempStr=preStr.substr(-preStr.length,(preStr.length-1)%digitGrouping+1);for(i=Math.floor((preStr.length-1)/digitGrouping);i>0;i–){tempStr+=groupingSymbol+preStr.substr(-i*digitGrouping,digitGrouping)}preStr=tempStr}if(leadingSymbol){preStr=leadingSymbol+preStr}if(isNeg){preStr=”-“+preStr}return preStr+decimalSymbol+postStr}

    myUberNumber;

  • Filip Vandueren

    March 1, 2021 at 2:30 pm

    If you create a dropdown menu controller, the result (.value) of those is an integer (1-n) of which item is selected.

    So you need to set up a dropdown menu with the options “period”, “comma”, “space” and use the value of that to get a value out of a fixed array (0 – n-1) that is also defined in your expression, and uses the corrsponding strings like so:

    dropdownValues=[".", ",", " "];
    dropdownindex=thisComp.layer("control").effect("thousands separator")("Menu").value;
    selectedValue = dropdownValues[dropdownindex-1];
Viewing 1 - 2 of 2 posts

Log in to reply.

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