Skip to main content
Participant
March 20, 2014
Question

Animate Number Counter - French Version

  • March 20, 2014
  • 1 reply
  • 627 views

I need help figuring out how to animate a number counter, but in french. I have the english version of my numbers animating up using the following algorithm:

numDecimals = 1;

commas = true;

dollarSign = true;

beginCount = 0;

endCount = 20.3;

dur = 2.5;

t = time - inPoint;

s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);

prefix = "";

if (s[0] == "-"){

  prefix = "-";

  s = s.substr(1);

}

if(dollarSign) prefix += " %";

if (commas){

  decimals = "";

  if (numDecimals < 1){

    decimals = s.substr(-(numDecimals + 1));

    s = s.substr(0,s.length - (numDecimals + 1));

  }

  outStr = s.substr(-s.length, (s.length-1)%3 +1);

  for (i = Math.floor((s.length-1)/3); i > 0; i--){

    outStr += "" + s.substr(-i*3,3);

  }

outStr + decimals +  prefix;

}else{

  prefix + s;

}

Right now the number counts from 0 to 20.3%, with a decimal inbetween 20 and 3. The french version I need to make is "20,3 %". Does anyone know how to manipulate this algorithm so it fits the french version - with the comma instead of the decimal?

This topic has been closed for replies.

1 reply

UQg
Legend
March 21, 2014

You can replace the line s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals); by:

s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals).replace(".", ",");

By the way your variable names are very confusing!

if(dollarSign) prefix += " %"; // it does work, but hell, that's circonvoluted !

Xavier.