How to Add Commas to Dynamic Numbers

Home Elementor 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!

More Free Resources

Join Our Community

Sign up to receive free resources in your inbox every week.

Wicky Design YouTube

Join Our Community

Never miss a post! Join now to receive helpful resources, tips, and tutorials in your inbox weekly. Registration is FREE and emails are delivered every Monday morning.