6 Replies Latest reply on Sep 12, 2017 1:09 PM by joshroseca

# Parsing number text string to numeric value

If I have the number "5" as a text layer, how can I get another text layer to read that number, and then add another number to it?

This gives me "56". I want "11".

temp = thisComp.layer("5").text.sourceText.value;

(temp + 6)

• ###### 1. Re: Parsing number text string to numeric value

I think I got it!  How's this?

temp = thisComp.layer("5").text.sourceText.value;

• ###### 2. Re: Parsing number text string to numeric value

I think I'd do it this way:

txt = thisComp.layer("5").text.sourceText;

parseInt(txt)+6

Dan

• ###### 3. Re: Parsing number text string to numeric value

Okay, just to complicate things, how would I add leading zeros? So I'd get 005, 010…

• ###### 4. Re: Parsing number text string to numeric value

This should work"

txt = thisComp.layer("5").text.sourceText;

numDigits = 3;

n =  parseInt(txt)+6;

s = n.toString();

while (s.length < numDigits) s = "0" + s;

Dan

• ###### 5. Re: Parsing number text string to numeric value

hey dan I combined both of your expression in to one: (worked better for me)

temp = thisComp.layer("5").text.sourceText;

numDigits = 3;

s = n.toString();

while (s.length < numDigits) s = "0" + s;

(my number is 1.11337 and I need to add 0.00003 to it...)

everything works beside the 0 digit thingy when it reaches 1.1140 for example.

tnxxx!

• ###### 6. Re: Parsing number text string to numeric value

Thanks Dan, this worked perfectly for me.