Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Parsing number text string to numeric value

Enthusiast ,
Jan 19, 2012 Jan 19, 2012

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)

TOPICS
Expressions
31.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 19, 2012 Jan 19, 2012

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

Translate
Enthusiast ,
Jan 19, 2012 Jan 19, 2012

I think I got it!  How's this?

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

add(temp, 6)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012

I think I'd do it this way:

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

parseInt(txt)+6

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 19, 2012 Jan 19, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2012 Jan 19, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 01, 2016 Sep 01, 2016

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

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

numDigits = 3;

n=add(temp, 0.00003);

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 12, 2017 Sep 12, 2017
LATEST

Thanks Dan, this worked perfectly for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines