Return-Path: Received: from mail-ie0-f174.google.com ([209.85.223.174] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP-TLS id 5041058 for AE-List@media-motion.tv; Wed, 17 Apr 2013 06:43:27 +0200 Received: by mail-ie0-f174.google.com with SMTP id 10so1486375ied.33 for ; Tue, 16 Apr 2013 21:51:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:x-gm-message-state; bh=cSxaf+UQ0gkAqwB6plq9rm6iazN7dP0CyOaFoDvicMw=; b=ed15Tshf63lRH/ViZT77VwHpw9lmF954CEDyUYlciP3xsV91/aiYBu6uLlyBqcR896 7uGLr22CEFNLrmaN4quzKy1n5NVUpHhhHCu8JfdkoY5aJL3NPIJ8n7G3rGAuJug/uT7g 6e7Xb/NtdlCqkUG7te1EJSL8Ge1Hnxbum1T5BMrfC7F+XnzlPP83yv8y4zgdyRiqWXcy myad+qhnMWIyRgwkFd7Op7W4Oe7K72VZOaJRknaSQsW99sp8+NkllHMKIJYGVi71VIG5 m7ojZv0QCARfl+WuJ4WMeGAnWDtXsTiZ9+hsI3x1vuf4CLmHQZ2nsDMOGUWVGoxwOY9l j7BQ== MIME-Version: 1.0 X-Received: by 10.50.22.3 with SMTP id z3mr3157203ige.80.1366174292627; Tue, 16 Apr 2013 21:51:32 -0700 (PDT) Received: by 10.64.12.52 with HTTP; Tue, 16 Apr 2013 21:51:32 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Apr 2013 21:51:32 -0700 Message-ID: Subject: Re: [AE] expressions: limiting decimals and adding 0 to single digit integers? From: Phil Spitler To: After Effects Mail List Content-Type: multipart/alternative; boundary=047d7b10caff6a32c904da873ddd X-Gm-Message-State: ALoCoQlNw2p9fO3RzDG3/6W2VYfjEbei7iN9lFvI5DKZj9o4HrFMFT8ItBO0oxASmle87CA5LWlJ --047d7b10caff6a32c904da873ddd Content-Type: text/plain; charset=ISO-8859-1 I'm sure there are many ways to do this, I'm not in front of my box right now but both these should work. To get the 2 decimal places you can use the toFixed(2) expression. sVal = "0" + sVal.toFixed(2); To get the leading 0 you could modify the line of code to: if (sVal < 10) {sVal = "0" + sVal.toFixed(2) } else {sVal = sVal.toFixed(2)}; I think I have the syntax right, but if not it might be pointer in the right direction. Phil On Tue, Apr 16, 2013 at 9:41 PM, James Culbertson wrote: > I am linking one layers rotation to a text layers source text. > > How do I modify the simple expression to limit the decimal to two places, > and at the same time make all integers two digits so 0 - 9 are 00, 01, > 02,...? > > Something like this but that adds two decimal places to the number: > > //--Expression begins > nums = thisComp.layer("shape").transform.rotation; > amtOfZeroes = 2; > //--Do not modify below this line > isNeg = false; > if(nums < 0) > { > nums = Math.abs( nums ); > isNeg = true; > } > sVal = Math.round( nums ) + ""; > while(sVal.length < amtOfZeroes) > { > sVal = "0" + sVal; > } > if(isNeg) > sVal = "-" + sVal; > > sVal > //--Expression ends > > > Thanks, James > > > +---End of message---+ > To unsubscribe send any message to > --047d7b10caff6a32c904da873ddd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I'm sure there are many ways to do this, I'm not i= n front of my box right now but both these should work.

To get the 2 decimal places you can use the toFixed(2) expression.

sVal =3D "0" + sVal.toFixed(2);
=

=
To g= et the leading 0 you could modify the line of code to:

<= /div>
if (= sVal < 10) {sVal =3D "0" + sVal.toFixed(2) } else=A0{sVal =3D =A0sVal.= toFixed(2)};

I think I have the syntax right, but if not it might = be pointer in the right direction.

=
Phil




=
On Tue, Apr 16, 2013 at 9:41 PM, James Culbertso= n <albion@speakeasy.net> wrote:
I am linking one layers rotation to a text l= ayers source text.

How do I modify the simple expression to limit the decimal to two places, a= nd at the same time make all integers two digits so 0 - 9 are 00, 01, 02,..= .?

Something like this but that adds two decimal places to the number:

//--Expression begins
nums =3D thisComp.layer("shape").transform.rotation;
amtOfZeroes =3D 2;
//--Do not modify below this line
isNeg =3D false;
if(nums < 0)
{
nums =3D Math.abs( nums );
isNeg =3D true;
}
sVal =3D Math.round( nums ) + "";
while(sVal.length < amtOfZeroes)
{
sVal =3D "0" + sVal;
}
if(isNeg)
sVal =3D "-" + sVal;

sVal
//--Expression ends


Thanks, James


+---End of message---+
To unsubscribe send any message to <ae-list-off@media-motion.tv>

--047d7b10caff6a32c904da873ddd--