Return-Path: Received: from asbnvacz-mailrelay01.megapath.net ([207.145.128.243] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP id 5043021 for AE-List@media-motion.tv; Thu, 18 Apr 2013 19:28:46 +0200 Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.53]) by asbnvacz-mailrelay01.megapath.net (Postfix) with ESMTP id BA4611EE5152 for ; Thu, 18 Apr 2013 13:36:55 -0400 (EDT) Received: (qmail 17157 invoked from network); 18 Apr 2013 17:36:55 -0000 Received: by simscan 1.4.0 ppid: 27553, pid: 26701, t: 0.2059s scanners: clamav: 0.88.2/m:52/d:13495 spam: 3.0.4 Received: from c-67-185-28-214.hsd1.wa.comcast.net (HELO [192.168.1.125]) (albion@[67.185.28.214]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 18 Apr 2013 17:36:55 -0000 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1283) Subject: Re: [AE] expressions: limiting decimals and adding 0 to single digit integers? From: James Culbertson In-Reply-To: Date: Thu, 18 Apr 2013 10:36:52 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <355F5D8B-CB2B-4195-BAC7-8B47F9B8B13D@speakeasy.net> References: To: "After Effects Mail List" X-Mailer: Apple Mail (2.1283) X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail8.sea5 X-Spam-Level: X-Spam-Status: No, score=0.0 required=8.0 tests=none autolearn=disabled version=3.0.4 Thanks Byron, Here's what finally worked: // get the value we want n =3D thisComp.layer("shape").transform.rotation.value; // add two zeros, and make it an unsigned string -- we'll add the = negative back later if it's supposed to be negative nScaled =3D Math.abs(Math.round(n * 100)); s =3D "" + nScaled.toString(); // pad low values with leading zeros to ensure at least 3 digits after = we move the decimal point while (s.length < 3) s =3D "0" + s; // if it was negative, add the - sign back if (n<0) s =3D "-" + s; // insert the decimal place before the last two decimal places s =3D s.substr(0,s.length-2) + "." + s.substr(s.length-2,s.length) Thanks to Walter Soyka over on the AE Creative Cow board. James On Apr 18, 2013, at 8:13 AM, Byron Nash wrote: > Try doing a Round or floor mized with multiplying it by 100 to get a = predictable number of zeroes.=20 >=20 > twoDigits =3D Math.round(num * 100) / 100; >=20 > Basically multiply your number by 100 for two zeroes and round it. = Then divide by 100 and you will have only two decimal places(rounded).=20= >=20 >=20 > On Wed, Apr 17, 2013 at 2:34 AM, James Culbertson = wrote: > And is there a way to force the decimals to always be there even when = they are XX.00 or XX.X0? >=20 > Thanks, >=20 > James >=20 >=20 > On Apr 16, 2013, at 11:12 PM, Zack Lovatt wrote: >=20 >> =46rom my understanding, this may be what you're looking for. Use = this instead of your existing code. Doesn't deal with the negative sign, = though; written hastily. In the morning I'll double check it and refine = it to add the negative! >>=20 >> nums =3D thisComp.layer("shape").transform.rotation.value.toFixed(2) = + ""; >>=20 >> if ((nums < 10) && (nums > -10)) nums =3D "0" + nums; >>=20 >> nums; >>=20 >> I am linking one layers rotation to a text layers source text. >>=20 >> 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,...? >>=20 >> Something like this but that adds two decimal places to the number: >>=20 >> //--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; >>=20 >> sVal >> //--Expression ends >>=20 >>=20 >> Thanks, James >>=20 >>=20 >> +---End of message---+ >> To unsubscribe send any message to >=20 >=20