Javascript Number subNum(n)

Description

Javascript Number subNum(n)


Number.prototype.subNum = function(n){
 var f_x = parseFloat(this);
 if (isNaN(f_x)){
  return false;/* www  .  j a v a2s .  com*/
 }

 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}



PreviousNext

Related