Nodejs Utililty Methods Number to Decimal Convert

List of utility methods to do Number to Decimal Convert

Description

The list of methods to do Number to Decimal Convert are organized into topic(s).

Method

toDecimal()
Number.prototype.toDecimal = function(){
  if(this > 0){
    return this / 100;
  }else{
    return this * 1;
};
toDecimal(value)
Number.prototype.toDecimal = function(value) { 
  var precision = 2; 
  var power     = Math.pow(10, precision || 0);
  return String(Math.round(value * power) / power);
};
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)
toMaxDecimal(d)
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)
kCnv(295)
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; 
...
toMillions()
Number.prototype.toMillions = function() {
  return (this / 1000000).toFixed(1) + 'M';
};