Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Numbers to text…

  • Numbers to text…

    Posted by Paul Maguire on May 8, 2008 at 3:06 pm

    Hi.

    I am trying to have a live text layer take the contents of another live text layer (an incremental counter) and output it as words eg. 15289 = “fifteen thousand two hundred and eighty-nine”

    Here’s an example of what I’ve done so far:

    tInteger = parseInt(thisComp.layer(“numbers”).text.sourceText);
    tTextString = [“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”, “eleven”, “twelve”, “thirteen”, “fourteen”, “fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”];
    text.sourceText = tTextString[tInteger];

    … then I stopped and realised it was far more complex than I had anticipated.

    So my question is – are there any pre-existing scripts out there which could help me out? Is there an easy solution? I’m sure someone must have had to tackle this before. BTW I’m using 6.5.

    Any help or pointers are most appreciated.

    Regards, Paul.

    Paul Maguire replied 18 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 8, 2008 at 8:53 pm

    Don’t say I never did anything for you. 🙂

    inputString = thisComp.layer(“numbers”).text.sourceText;

    lessThanTwenty = [“zero”,”one”,”two”,”three”,”four”,
    “five”,”six”,”seven”,”eight”,”nine”,
    “ten”,”eleven”,”twelve”,”thirteen”,”fourteen”,
    “fifteen”,”sixteen”,”seventeen”,”eighteen”,”nineteen”];

    tens = [“zero”,”ten”,”twenty”,”thirty”,”forty”,”fifty”,”sixty”,”seventy”,”eighty”,”ninety”];

    groups = [“”, “thousand”, “million”, “billion”, “trillion”];

    function processThreeDigits(theString, theSuffix){
    s = “”;
    if (theString.length > 2 && parseInt(theString[0]) > 0){
    s = ” ” + lessThanTwenty[parseInt(theString[0])] + ” hundred”;
    }
    remainder = parseInt(theString%100,10);
    if (remainder > 19){
    s = s + ” ” + tens[Math.floor(remainder/10)];
    ones = remainder%10;
    if (ones > 0){
    s = s + ” ” + lessThanTwenty[ones];
    }
    }else if (remainder > 0){
    s = s + ” ” + lessThanTwenty[remainder];
    }
    if (s.length > 0) return s + ” ” + theSuffix;
    return s;
    }

    outputString = “”;

    tempString = inputString;
    groupIdx = 0;

    while (tempString.length > 0){
    outputString = processThreeDigits(tempString.substr(-3),groups[groupIdx]) + outputString;
    tempString = tempString.substr(0,tempString.length-3);
    groupIdx++;
    }

    outputString

    Dan

  • Paul Maguire

    May 9, 2008 at 9:50 am

    Dan.

    What can I say? I wasn’t expecting a full script, but just some pointers. It’s perfect. I’ll study this script and learn a lot from it.

    I very much appreciate your generosity. Any time you happen to be in Glasgow, Scotland – please let me know and I’ll buy you dinner!

    Best wishes, Paul.

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