Mailing List AE-List@media-motion.tv ? Message #48541
From: James Culbertson <albion@speakeasy.net>
Subject: Re: [AE] expressions: limiting decimals and adding 0 to single digit integers?
Date: Tue, 16 Apr 2013 22:16:55 -0700
To: After Effects Mail List <AE-List@media-motion.tv>
I'm not savvy enough to figure out how to integrate this into the existing expression. I keep getting errors.

Thanks,

James


On Apr 16, 2013, at 9:51 PM, Phil Spitler wrote:

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 <albion@speakeasy.net> 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 <ae-list-off@media-motion.tv>


 
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to ListMaster