How to Add Commas to Dynamic Numbers

August 15, 2022

In this Elementor tutorial I will show you how to add commas automatically to larger numbers. This is really helpful if you are displaying large dynamic data and need to display it correctly on the front end.

CodePen:
https://codepen.io/engza/pen/jOyOYK

Timestamps:

  • 0:00 Introduction
  • 0:50 Elementor Tutorial Begins

JavaScript Code:

				
					<script>
jQuery(function($){
   function numberWithCommas(number) {
    var parts = number.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}
  $(document).ready(function() {
  $("#wicky h2,#wickydesign h2").each(function() {
    var num = $(this).text();
    var commaNum = numberWithCommas(num);
    $(this).text(commaNum);
  });
});
});
</script>
				
			

*Some of the links on this page are affiliate links, meaning we may receive a commission if you follow them. This allows us to continue providing free content and educational resources for you. Thank you for supporting our small business!

Share this post:

Facebook
Reddit
Twitter
Pinterest
LinkedIn
Email

Sign-up for our Newsletter

Receive members-only discounts to our shop, notifications about live events, tips, tricks, news, and more! Sign up is FREE. Join today!

More Free Resources