bfintal / Counter-Up

Counter-Up is a lightweight jQuery plugin that counts up to a targeted number when the number becomes visible.
http://bfintal.github.io/Counter-Up/demo/demo.html
GNU General Public License v2.0
746 stars 722 forks source link

European "." and "," #15

Open Guaito opened 9 years ago

Guaito commented 9 years ago

Can you manage also the european number format (opposite to english) in terms of "." and "," inside numbers? i.e.:

Thanks in advance

Blacksnipe commented 8 years ago

Hi,

I was looking for this, too. Since I saw there was not much of feedback, I thought I'd look for it myself.

Might not be the most suitable solution, but I've added:

newNum = newNum.replace(/\./g, settings.commaSeparator);

after:

newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);

inside the if (isFloat) {}-statement.

I've also added a couple of parameters to the settings for re-use, which you can adjust whenever you call the function:

    // Defaults
    var settings = $.extend({
      'time': 400,
      'delay': 10,
      'commaSeparator': '.',
      'thousandSeparator': ','
    }, options);
ciromattia commented 8 years ago

In my fork I merged a bunch of PRs - it's already on bower and NPM. You can get this with the new "formatter" option, for example if you have no decimals:

$('.counter').counterUp({
  delay: 100,
  time: 1600,
  formatter: function (n) {
  return n.replace(/,/g, '.');
});

Feel free to mangle the regex for decimal support.