Nodejs Number Calculate fillZero(len)

Here you can find the source of fillZero(len)

Method Source Code

Number.prototype.fillZero = function (len)
{
   var s = this.toString(10);
   while (s.length<len) s = "0" + s;
   return s;/*www  .j a va  2s. c  o m*/
}

Related

  1. double()
    Number.prototype.double = function() {
      return this * 2;
    };
    
  2. doubleDigitalize()
    "use strict";
    Number.prototype.doubleDigitalize = function() {
      const numberString = this.toString();
      return numberString.length < 2 ? "0" + numberString : numberString;
    };
    
  3. equals(another)
    Number.prototype.equals = function (another) {
        return this - another === 0;
    };
    
  4. exp()
    Number.prototype.exp = function() {
      return Math.exp(this);
    };
    
  5. fe(x)
    Number.prototype.fe = function(x)
      var s = x.toString();
      var point = s.search(/\./);
      if (point == -1)
        return (Math.abs(this - x) < 0.5);    
      else
    ...
    
  6. firstDigit()
    Number.prototype.firstDigit = Number.prototype.firstDigit || function () {
      let number = this;
      while (number >= 10) {
        number = Math.floor(number / 10);
      return number;
    };
    
  7. fix(n)
    Number.prototype.fix = function (n) {
        var val = String(this);
        n = Math.abs(n);
        val = val.split('.');
        val[1] = val[1] || '';
        var m = val[1].length;
        if (m < n) {
            m = n - m;
            while (m > 0) {
    ...
    
  8. fizz()
    Number.prototype.fizz = function() {
        return this % 3 === 0 ? "fizz" : "";
    };
    Number.prototype.buzz = function() {
        return this % 5 === 0 ? "buzz" : "";
    };
    for (var i = 1; i <= 15; i++) {
        var candidate = Number(i).fizz() + Number(i).buzz();
        console.log(candidate ? candidate : i);
    ...
    
  9. float()
    var num = 5;
    Number.prototype.float = function(){ 
          return this.toFixed(2);
    Number.prototype.int = function(){ 
          return parseInt(this) ;
    console.log(num.float());
    console.log(num);
    ...