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

Parsing number text string to numeric value

Enthusiast ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

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

Views

29.0K

Translate

Translate

Report

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

Votes

Translate

Translate
Enthusiast ,
Jan 19, 2012 Jan 19, 2012

Copy link to clipboard

Copied

I think I got it!  How's this?

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

add(temp, 6)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I think I'd do it this way:

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

parseInt(txt)+6

Dan

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks Dan, this worked perfectly for me.

Votes

Translate

Translate

Report

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