Nodejs Number Convert toS()

Here you can find the source of toS()

Method Source Code

function numberToPx(number) {
   return number + "px"; 
}

function getMilliseconds(timestampStr) {
   var timestampStrSplit = timestampStr.split(".");
   var milli = Date.parse("January 1, 1970 " + timestampStrSplit[0] + " UTC");
   if (timestampStrSplit.length == 1)
      return milli;
   else (timestampStrSplit.length == 2)
      return milli + parseInt(timestampStrSplit[1] * 100);
}

function getSeconds(timestampStr) {
   return getMilliseconds(timestampStr) / 1000;
}

Number.prototype.toS = function() {
   return this.valueOf() / 1000;
}

Number.prototype.toMS = function() {
   return ~~(this.valueOf() * 1000);
}

Related

  1. toDollars(c, printSign)
    Number.prototype.toDollars = function(c, printSign){
      var n = this,
        c = isNaN(c = Math.abs(c)) ? 2 : c,
        d = ".",
        t = ",",
        s = n < 0 ? "-" : "",
        i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
        j = (j = i.length) > 3 ? j % 3 : 0,
        sign = printSign ? '$': '';
    ...
    
  2. toMinutes()
    Number.prototype.toMinutes = function(){
      return (Math.floor(parseInt(this)/60)).addTrailingZero()+":"+(parseInt(this)%60).addTrailingZero();
    };
    
  3. toNumber( val )
    var NumberUtils = new function() {
        this.toNumber = function( val ) {
            if(val==null || val=="") return null;
        val = val.replace(',', '');
            return eval(val);
        this.toInteger = function( val ) {
        val = val.replace(',', '');
            return parseInt(val, 10); 
    ...
    
  4. toPrecisionFixed(precision)
    Number.prototype.toPrecisionFixed = function(precision) {
      var n = this.toPrecision(precision);
      n = n.replace(/(.+)e\+(.+)/, function(n, sig, exp) {
        sig = sig.replace(/\./, '');       
        l = sig.length - 1;
        while (exp-- > l) sig = sig + '0'; 
        return sig;
      });
      n = n.replace(/(.+)e-(.+)/, function(n, sig, exp) {
    ...
    
  5. toPrecision(length)
    Number.prototype.toPrecision = function toPrecision(length) {
        return parseFloat(this.toFixed(length));
    };
    
  6. to_feet()
    Number.prototype.to_feet = function() {
      return this / 0.3048;
    };