Tip for rounding numbers
Posted: August 8th, 2006, 11:15 pm
Hi all,
we often have to round numbers in our scripts (or expressions). I usually use the Math.round() method to accomplish this, for example:
Yesterday I've found an alternative way to round numbers with a defined precision: the to.Fixed() Javascript method. It's recognized by AE in scripts and expressions as well.
Example:
Of course setting the precision to 0, is equivalent to the Math.round() method. [position[0].toFixed(0),position[1].toFixed(0)]
I guess some of you already know this method but I don't remember to have seen it already in a script so ...
we often have to round numbers in our scripts (or expressions). I usually use the Math.round() method to accomplish this, for example:
Code: Select all
x = 57.351245;
alert(Math.round(x*100)/100); // 2-digit precision -> 57.35
Example:
Code: Select all
pi = 3.14159;
alert(pi.toFixed(2)); // 2-digit precision -> 3.14
I guess some of you already know this method but I don't remember to have seen it already in a script so ...