0

I am developing a website using html, css, jQuery.

I am trying to show some stats that will be kind of numbers say: 376766 user registered

But I am doing it by data- attribute:

<strong class="datafill1" data-to="">0</strong>

Here I pass data-to by a random script generator.

Problem is that I want to separate numbers by comma but I am not able to do

Please help me

  • Current Format :376766
  • Desired Format : 3,76,766

I am trying it but not able to do it :(

Update : Here is the script: //-------------------------fake counter 1

function fakecounter1(){

//decrease/increase counter value (depending on perceived popularity of your site!)
var decrease_increase=11439

var counterdate=new Date()
var currenthits=counterdate.getTime().toString()
currenthits=parseInt(currenthits.substring(2,currenthits.length-4))+decrease_increase

var df1=currenthits -2746740;
$('.datafill1').attr('data-to', df1);
}
fakecounter1()
ashi
  • 108
  • 11
  • Can we see the said-`random script generator`? – D4V1D Mar 27 '15 at 16:37
  • You can pass any string to a data-attribute but you cannot adjust the number pattern with CSS once it's in there...at least as far as I know. – Paulie_D Mar 27 '15 at 16:52
  • @Paulie_D please have a look on updated que. – ashi Mar 27 '15 at 17:00
  • I think you 'd need to do some initial parsing to break the number up before passing that string to the attribute. There are plugins to do that. or pure JS - http://www.mredkj.com/javascript/numberFormat.html – Paulie_D Mar 27 '15 at 17:06
  • here is live link http://sigrideducation.com/btpwebsitenew/ – ashi Mar 27 '15 at 17:15
  • possible duplicate of [Add comma to numbers every three digits using jQuery](http://stackoverflow.com/questions/1990512/add-comma-to-numbers-every-three-digits-using-jquery) – hoss Mar 27 '15 at 17:52

1 Answers1

0

I'm not sure what you are asking but I think you want to get a number printed with commas as thousands separators (which according to your Desired Format example is not what you want but I am assuming a typo.)

JavaScript code to display an integer with commas:

var d = 1234567;
var s = (''+d).replace(/(\d)(?=(\d\d\d)+$)/g, "$1,"); // 1,234,567

The result is obviously a string.

sebnukem
  • 8,143
  • 6
  • 38
  • 48