Skip to content

Number format #2

@therotten24

Description

@therotten24

Hi and thanks for reading me
First of all I would like to thank you for the template you have created, since I find it incredible and quite useful
I have an issue with the number format on the first tab. I would like to include commas in the numbers to make them easier to read, but I haven't found a way to do it I tried incluiding this to the JQuery code:

(function($) {
    $.fn.countTo = function(options) {
        // merge the default plugin settings with the custom options
        options = $.extend({}, $.fn.countTo.defaults, options || {});

        // how many times to update the value, and how much to increment the value on each update
        var loops = Math.ceil(options.speed / options.refreshInterval),
            increment = (options.to - options.from) / loops;

        return $(this).each(function() {
            var _this = this,
                loopCount = 0,
                value = options.from,
                interval = setInterval(updateTimer, options.refreshInterval);

            function updateTimer() {
                value += increment;
                loopCount++;
                $(_this).html(value.toFixed(options.decimals));

                if (typeof(options.onUpdate) == 'function') {
                    options.onUpdate.call(_this, value);
                }

                if (loopCount >= loops) {
                    clearInterval(interval);
                    value = options.to;

                    if (typeof(options.onComplete) == 'function') {
                        options.onComplete.call(_this, value);
                    }
                }
            }
        });
    };

    $.fn.countTo.defaults = {
        from: 0,  // the number the element should start at
        to: 100,  // the number the element should end at
        speed: 500,  // how long it should take to count between the target numbers
        refreshInterval: 100,  // how often the element should be updated
        decimals: 0,  // the number of decimal places to show
        onUpdate: null,  // callback method for every time the element is
        
        updated,
        onComplete: null,  // callback method for when the element finishes
        updating,
        formatter: function(value, options) {
    //default: return value.toFixed(options.decimals);
    return value.toFixed(options.decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  }
    };
})(jQuery);

But it doesn't work. I am doing something wrong?

Thanks for the help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions