Home › Forums › Porto – Responsive HTML5 Template › Thousands Separator in Counters
- This topic has 4 replies, 2 voices, and was last updated 3 years, 9 months ago by
JohnAlan. This post has been viewed 1710 times
-
AuthorPosts
-
August 8, 2022 at 12:28 am #10040859
JohnAlan
ParticipantHi,
With the counters as used on https://www.okler.net/previews/porto/9.7.0/demo-one-page-agency.html, can a thousands separator (,) be used, so that it would end up as (e.g.): –
30,000+ SUPPORT HOURS
10+ YEARS IN BUSINESS
40,000+ HAPPY CLIENTS
7,000+ DEVELOPMENT HOURS?
Thanks in advance,
John.
Template Version: 9.7.0August 8, 2022 at 8:54 pm #10040864Support
KeymasterHello, you can find examples below:
<div class="row"> <div class="col"> <div class="row counters"> <div class="col-sm-6 col-lg-3 mb-4 mb-lg-0"> <div class="counter counter-primary"> <strong data-to="70.13" data-plugin-options="{'decimals': 2}">0</strong> <label>Decimals</label> </div> </div> <div class="col-sm-6 col-lg-3 mb-4 mb-lg-0"> <div class="counter counter-with-unit counter-primary"> <strong>$</strong> <strong data-to="15">0</strong> <label>Currency</label> </div> </div> <div class="col-sm-6 col-lg-3 mb-4 mb-sm-0"> <div class="counter counter-with-unit counter-primary"> <strong data-to="78">0</strong> <strong>%</strong> <label>Percentual</label> </div> </div> <div class="col-sm-6 col-lg-3"> <div class="counter counter-primary"> <strong data-to="5000" data-append="+">0</strong> <label>Append Symbol</label> </div> </div> </div> </div> </div>Let me know if you need further assistance.
Kind Regards,
Jonas
August 8, 2022 at 9:05 pm #10040866JohnAlan
ParticipantThanks, but none of these examples add a thousands separator (comma) to format the number correctly (e.g. 5,000)?
August 8, 2022 at 9:20 pm #10040868Support
KeymasterHi,
Try with this code:
HTML:
<div class="row counters"> <div class="col-sm-6 col-lg-3 mb-4 mb-lg-0"> <div class="counter"> <strong data-to="30000" data-plugin-options="{'millionFormat': true}">0</strong> </div> </div> </div>JS (js/custom.js):
$.extend(theme.PluginCounter.prototype, { build: function() { if (!($.isFunction($.fn.countTo))) { return this; } var self = this, $el = this.options.wrapper; $.extend(self.options, { onComplete: function() { if ($el.data('append')) { $el.html($el.html() + $el.data('append')); } if ($el.data('prepend')) { $el.html($el.data('prepend') + $el.html()); } } }); $el.appear(function() { if( self.options.millionFormat ) { $.extend(self.options, { formatter: function (value, options) { value = value.toFixed(options.decimals); value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ','); return value; } }); } $el.countTo(self.options); }, { accX: self.options.accX, accY: self.options.accY }); return this; } });Let me know if you need further assistance.
Best Regards,
Okler Themes
August 8, 2022 at 11:22 pm #10040869JohnAlan
ParticipantExcellent, thanks again!
-
AuthorPosts
This topic is marked as "RESOLVED" and can not rceive new replies.
