Jquery thousand separator

Active3 hr before
Viewed126 times

6 Answers


How to print a number with commas as thousands separators in JavaScript ? ,The best way is to split the number format into several parts, ,Use this function to overcome all the NumberFormat issues, This function adds commas in undesirable places if there are more than 3 digits after the decimal point

Example_snippet/controller/utility/_jquery.js/ <!DOCTYPE html> <html> <head> . . .
<!DOCTYPE html>

   <meta charset="utf-8">
   <title>To print an integer with commas as thousands separators</title>



load more v

This will add thousand separators while retaining the decimal part of a given number:,best and simple way to format the number is to use java-script function,You could also probe for the locale's decimal separator with:,Please be sure to answer the question, Provide details and share your research!

Example_snippet/controller/utility/_jquery.js/ function addCommas(nStr) { . . .
function addCommas(nStr) {
   nStr += '';
   var x = nStr.split('.');
   var x1 = x[0];
   var x2 = x.length > 1 ? '.' + x[1] : '';
   var rgx = /(\d+)(\d{3})/;
   while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
   return x1 + x2;
load more v

Example_snippet/controller/utility/_jquery.js/ function numberWithCommas(x) {. . .
function numberWithCommas(x) {
   return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
load more v

I would like to introduce the jQuery LazzyNumeric plugin which extends jQuery autoNumeric (http://www,decorplanit

Example_snippet/controller/utility/_jquery.js/ <form action="" method="post">. . .
<form action="" method="post">
         <td><input type="text" name="item_qty" class="numeric" /></td>
         <td>Price 1</td>
         <td><input type="text" name="item_price1" class="numeric" /></td>
         <td>Price 2</td>
         <td><input type="text" name="item_price2" class="numeric" /></td>
   <br />
   <input type="submit" name="submit" id="submit" />
<script language="javascript" type="text/javascript">
   // Use this code to activate the thousand separator format.
load more v

The format() method of this object can be used to return a string of the number in the specified locale and formatting options, This will format the number with commas at the thousands of places and return a string with the formatted number

Example_snippet/controller/utility/_thousand.js/ nfObject = new Intl.NumberForm. . .
nfObject = new Intl.NumberFormat('en-US')
load more v

1, Download and put the JavaScript file easy-number-separator

Example_snippet/controller/utility/_thousand.js/ <script src="https://code.jque. . .
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous">
<script src="easy-number-separator.js"></script>
load more v