Adding thousand separator to jQuery Counter

user3088202

I am trying to add commas (thousand separator) for big numbers that use the follow counter function:

<script type='text/javascript'>
    $(window).load(function() {
        $('.Count').each(function() {
            var $this = $(this);
            jQuery({Counter: 0}).animate({Counter: $this.text()}, {
                duration: 1500,
                easing: 'swing',
                step: function() {
                    $this.text(Math.ceil(this.Counter));
                }
            });
        });
    });

Do I modify this particular formula or do I have to write an additional function that will handle the formatting?

pizzarob

this might work

<script>
$(window).load(function() {
    $('.Count').each(function() {
        var $this = $(this);
        jQuery({Counter: 0}).animate({Counter: $this.text()}, {
            duration: 1500,
            easing: 'swing',
            step: function() {
                var num = Math.ceil(this.Counter).toString();
                if(Number(num) > 999){
                    while (/(\d+)(\d{3})/.test(num)) {
                        num = num.replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
                    }
                }
                $this.text(num);
            }
        });
    });
});
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set global thousand separator on knitr

From Dev

Adding thousand separator while printing a number

From Dev

How to format number with "." as thousand separator, and "," as decimal separator?

From Dev

validate decimal with decimal separator and thousand separator

From Dev

Regex valid numbers with thousand separator

From Dev

Python replace middle digits with commas thousand separator

From Dev

Formatting thousand separator for integers in a pandas dataframe

From Dev

d3.format thousand separator on variables?

From Dev

regex for multiple formats decimals and thousand separator

From Dev

Thousand separator not working right way

From Dev

Is it possible to print a number formatted with thousand separator in Rust?

From Dev

Format number with space as thousand separator

From Dev

Adding Thousand Separator to Int in Swift

From Dev

Decimal not showing group(thousand) separator after parse

From Dev

ExtJS 6 thousand separator in number field

From Dev

Counter with thousands separator

From Dev

Regular expression for thousand separator without decimal point

From Dev

Remove thousand separator from string

From Dev

dot instead of comma as thousand separator

From Dev

Thousand Separator in DBGrid

From Dev

Thousand separator with wide/unicode stream

From Dev

Regex valid numbers with thousand separator

From Dev

Adding thousand separator to extracted website data

From Dev

Thousand separator not working right way

From Dev

Devexpress XRtableCell thousand separator?

From Dev

Thousand separator in awk

From Dev

Format number with space as thousand separator

From Dev

Adding Thousand Separator Automatically (Swift)

From Dev

String Number format with "/" for thousand separator

Related Related

HotTag

Archive