javascript - Formatting a number to include a thousands-separting comma -


i working on project @ work want format values on table (128879) (128,879). code have used far is:

$(document).ready(function(){ $('#tableone tr td:nth-child(3)').each(function(){     var num = $(this).text;     num.tostring().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") }); }); 

also, tried jquery numberformatter library, error code shows jquery not defined (the last line of code on debugger page using chrome) , math.js (no luck). not sure why happening.

the <script> tag used jquery , math.js shown below:

<script type = 'text/javascript' src ="jquery.numberformatter-1.2.4.min.js"></script> <script type="text/javascript" src="math.js"></script> 

you need include jquery library can use $ want. also, $(this).text function; want num = $(this).text() , $(this).text(num.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")). have not tested regex, don't know if work.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -