Nodejs Number Calculate subNum(n)

Here you can find the source of subNum(n)

Method Source Code

Number.prototype.subNum = function(n){
   var f_x = parseFloat(this);
   if (isNaN(f_x)){
      return false;
   }/*from   ww w  .j  a  va2  s .c  om*/
   f_x = Math.floor(f_x*Math.pow(10,n)+0.0001)/Math.pow(10,n);
   var s_x = f_x.toString();
   var pos_decimal = s_x.indexOf('.');
   if (pos_decimal < 0){
      pos_decimal = s_x.length;
      s_x += '.';
   }
   while (s_x.length <= pos_decimal + n){
      s_x += '0';
   }
   return s_x;
}

function subNumFun(a,b){
   return a.subNum(b)
}

export {subNumFun}

Related

  1. snap(resolution)
    Number.prototype.snap = function(resolution) {
      return Math.floor(this / resolution) * resolution;
    };
    
  2. sqrt()
    Number.prototype.sqrt = function() {
      return Math.sqrt(this);
    };
    
  3. square()
    var expect = chai.expect;
    Number.prototype.square = function () {
        "use strict";
        return this * this;
    };
    
  4. square()
    Number.prototype.square = function() {
      return this * this;
    };
    
  5. step(to, add_remove_step)
    Number.prototype.step = function (to, add_remove_step) {
      var from = this.valueOf();
      var ch = add_remove_step.match(/[\+,\-]/g)[0];
      var i = from;
      var arr = [];
      if (ch === '+') {
        while (i <= to) {
          arr.push(i);
          i = i + parseInt(add_remove_step);
    ...
    
  6. succ()
    Number.prototype.succ = function() {
        return this + 1;
    };
    
  7. tan()
    Number.prototype.tan = function() {
        return Math.tan(this);
    
  8. testNumber()
    function Number(){
      this.start = 20
      this.testNumber();
      this.answer = 1
    };
    Number.prototype.testNumber = function(){
      var i = 1;
      var start = this.start;
      while(i <= 20){
    ...
    
  9. trim(a, b)
    Number.prototype.trim = function(a, b) {
      var min = Math.min(a, b),
          max = Math.max(a, b);
      return Math.min(Math.max(parseInt(this, 10), min), max);
    };