|
|
Thanks Byron,
Here's what finally worked:
// get the value we want
n = 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 = Math.abs(Math.round(n * 100));
s = "" + 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 = "0" + s;
// if it was negative, add the - sign back
if (n<0) s = "-" + s;
// insert the decimal place before the last two decimal places
s = 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.
>
> twoDigits = Math.round(num * 100) / 100;
>
> 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).
>
>
> On Wed, Apr 17, 2013 at 2:34 AM, James Culbertson <albion@speakeasy.net> wrote:
> And is there a way to force the decimals to always be there even when they are XX.00 or XX.X0?
>
> Thanks,
>
> James
>
>
> On Apr 16, 2013, at 11:12 PM, Zack Lovatt wrote:
>
>> From 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!
>>
>> nums = thisComp.layer("shape").transform.rotation.value.toFixed(2) + "";
>>
>> if ((nums < 10) && (nums > -10)) nums = "0" + nums;
>>
>> nums;
>>
>> 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>
>
>
|
|