Nodejs Float Format to2Digits()

Here you can find the source of to2Digits()

Method Source Code

Number.prototype.to2Digits = function () {
   return this.toFixed(2).toString().replace(".", ",");
};

Related

  1. toFixedDown(digits)
    Number.prototype.toFixedDown = function(digits) {
      var re = new RegExp('(\\d+\\.\\d{' + digits + '})(\\d)'),
          m = this.toString().match(re);
      return m ? parseFloat(m[1]) : this.valueOf();
    };
    
  2. toFixedtoFixed
    function toFixed(num){
      var divisor = parseInt(1 + "0".repeat(num));
      return Math.round(this*divisor)/divisor
    Number.prototype.toFixed = toFixed
    
  3. toFloorFixed(accuracy)
    Number.prototype.toFloorFixed = function (accuracy) {
      var k = Math.pow(10, accuracy)
      return (Math.floor(this * k) / k).toString()
    Date.prototype.toInternetTime = function (accuracy) {
      const BeatInSeconds = 86.4
      const utcHours = this.getUTCHours()
      const hours = utcHours !== 23 ? utcHours + 1 : 0
      const BielMeanTime = this.getUTCSeconds() + this.getUTCMinutes() * 60 + hours * 3600
    ...
    
  4. toNumFixed(num)
    Number.prototype.toNumFixed = function (num) {
      return parseFloat(this.toFixed(num));
    
  5. splitThousands()
    Number.prototype.splitThousands = function () {
        var s = this.toString();
        var thousands = Math.floor(this / 1000).toString();
        return this > 999 ? ("{0} {1}").format(thousands, s.slice(thousands.length, s.length)) : s;
    };