Groups > Multimedia > Adobe After Effects expressions > Re: Yet Another counting numbers question ->




Yet Another counting numbers question -

Yet Another counting numbers question -
Sat, 13 Oct 2007 15:04:03 -070
I often use Rick's incredibly useful 100 billion number counting expression.


s = effect("value")("Slider");
m = effect("multiplier")("Slider"); //use for numbers
greater than 1 million
v = s*m; //value of counter

function digits(Val, Digits)
{var n = Val.toString();
  while (n.length < Digits) n = '0' + n; return n;}

h = Math.floor(v);
t = Math.floor(h / 1000);
m = Math.floor(t / 1000); = Math.floor(m / 1000);

hd = digits(h-t * 1000, 3);
td = digits(t-m * 1000, 3);
md = digits(m-b * 1000, 3);

if (v < 1000)  else if (v < 1000000) {t + "," + hd} else if
(v < 1000000000) {m + "," + td + "," + hd} else {b +
"," + md + "," + td + "," + hd}



But how do I add enough leading zeroes to whatever number I'm counting up to?

Post Reply
Re: Yet Another counting numbers question ->
Sat, 13 Oct 2007 15:58:54 -070
The easiest way I can think of without rewriting the code would be to simply
mask off the first digit. IOW, if you want to your count to be to a million then
you'd actually count from 10 million to 11 million. You'd simply mask off the
first 1.

Post Reply
Re: Yet Another counting numbers question ->
Sat, 13 Oct 2007 17:21:49 -070
Post Reply
Re: Yet Another counting numbers question ->
Sat, 13 Oct 2007 18:01:10 -070
Hmmmm... maybe I stated my question unclearly. It wouldn't be the first time!
;)

I'm looking to do an expression based number counter that has leading zeros and
decimal places.

I can get to the decimal places with this Rick Gerard expression:


places = 1; //number of decimal places desired
val = effect("Slider Control")("Slider"); //sub in the name
of your slider here

factor = Math.pow(0.1, places) ;
sign = "";
if (val < 0) sign = "-";

val = Math.abs(val);
whole = Math.floor(val);
fraction = "" + Math.round((val - whole)/factor)*factor;

for (fraction; fraction.length < places+2; fraction+="0");

sign + whole + "." + fraction.substring(2, places+2)


But I don't know how to do leading zeroes. (So 45.32 would read 0045.32)
Post Reply
Re: Yet Another counting numbers question ->
Sat, 13 Oct 2007 18:50:09 -070
The idea is to add an order of magnitude to the value. So, in your instance, add
10000 to the value, which will give you 10045.32. Then after you generate your
string, chop off the leading 1 using substring. The modified code would look
something like this:

places = 2; //number of decimal places desired
order = 4; //order of magnitude
val = effect("Slider Control")("Slider"); //sub in the name
of your slider here
val+=Math.pow(10, order);
factor = Math.pow(0.1, places) ;
sign = "";
if (val < 0) sign = "-";

val = Math.abs(val);
whole = Math.floor(val);
fraction = "" + Math.round((val - whole)/factor)*factor;

for (fraction; fraction.length < places+2; fraction+="0");

str = sign + whole + "." + fraction.substring(2, places+2);
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact