Creative COW SIGN IN & SETTINGS :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

Numbers to text...

Cow Forums : Adobe After Effects Expressions
Numbers to text...
by Paul Maguire on May 8, 2008 at 3:06:44 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.

Respond to this post     Return to posts index

Re: Numbers to text...
by Dan Ebberts on May 8, 2008 at 8:53:49 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



Respond to this post     Return to posts index

Re: Numbers to text...
by Paul Maguire on May 9, 2008 at 9:50:53 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.



Respond to this post     Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSLIBRARYPODCASTSBLOGSMAGAZINESERVICESNEWSLETTERSNEWSSTOREEVENTS

© CreativeCOW.net All rights are reserved.

[Top]