Nodejs Number to Decimal Convert toMaxDecimal(d)

Here you can find the source of toMaxDecimal(d)

Method Source Code

var k2c = k => k - 273.15
var k2r = k => k * 1.8
var k2f = k => k2r(k) - 459.67

Number.prototype.toMaxDecimal = function (d) {
   return +this.toFixed(d) + ''
}

function kCnv(k) {
   document.write( k,'K? = ', k2c(k).toMaxDecimal(2),'C? = ', k2r(k).toMaxDecimal(2),'R? = ', k2f(k).toMaxDecimal(2),'F?<br>' )
}

kCnv(21)/* w  ww. j ava 2  s  .  c  om*/
kCnv(295)

Related

  1. toDecimal()
    Number.prototype.toDecimal = function(){
      if(this > 0){
        return this / 100;
      }else{
        return this * 1;
    };
    
  2. toDecimal(value)
    Number.prototype.toDecimal = function(value) { 
      var precision = 2; 
      var power     = Math.pow(10, precision || 0);
      return String(Math.round(value * power) / power);
    };
    
  3. toDecimalPrecision(number_of_decimal_places)
    Number.prototype.toDecimalPrecision = function(number_of_decimal_places) {
      var components = ("" + this).split('.')
      if (components[0] == undefined) components[0] = "0";
      if (components[1] == undefined) components[1] = "0";
      return components[0] + '.' + components[1].substr(0,number_of_decimal_places)
    
  4. toMaxFiexed(digits)
    Number.prototype.toMaxFiexed = function (digits) {
      var ret = this.toFixed(digits);
      ret = ret.replace(/0+$/, '').replace(/\.$/, '');
      return ret;
    function HTMLEncode (input) { 
      var converter = document.createElement("DIV"); 
      converter.innerText = input; 
      var output = converter.innerHTML; 
    ...
    
  5. toMillions()
    Number.prototype.toMillions = function() {
      return (this / 1000000).toFixed(1) + 'M';
    };