Javascript Number digits()

Description

Javascript Number digits()


var util = require('util'),
 _ = require('underscore')

Number.prototype.digits = function() {
    return (Math.floor(this)+"").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
};

var SampleBolt = module.exports = function (field, every) {
 var count = 0;/*  w  w  w  . j  a  v a 2 s.  co  m*/
 var startTime = new Date();

 return {
  execute: function(d, callback) {

   count += 1;
   if (count % every == 0) {
      var endTime = new Date();
      var ms = endTime - startTime;
         console.log("%s events (%s ms @ %s per minute)", count, ((count/ms)*1000).digits(), ((count/ms)*1000*60).digits());
     }
  }
 }
}



PreviousNext

Related