Nodejs Float Format toFloorFixed(accuracy)

Here you can find the source of toFloorFixed(accuracy)

Method Source Code

// http://www.swatch.com/en_us/internet-time
// https://en.wikipedia.org/wiki/Swatch_Internet_Time
// http://time.interordi.com/itime.php
// http://www.timeanddate.com/time/internettime.html

Number.prototype.toFloorFixed = function (accuracy) {
  var k = Math.pow(10, accuracy)
  return (Math.floor(this * k) / k).toString()
}

// original work by Paul Philippov (https://themactep.com/beats/js)
Date.prototype.toInternetTime = function (accuracy) {
  const BeatInSeconds = 86.4//ww  w .ja  va  2s  .c  o  m

  const utcHours = this.getUTCHours()
  const hours = utcHours !== 23 ? utcHours + 1 : 0

  const BielMeanTime = this.getUTCSeconds() + this.getUTCMinutes() * 60 + hours * 3600
  const beats = Math.abs(BielMeanTime / BeatInSeconds).toFloorFixed(parseInt(accuracy))

  const length = accuracy > 0 ? accuracy + 1 : 0

  return '@'.concat('000'.concat(beats).slice(beats.length - length))
}

Related

  1. toFixed10(precision)
    Number.prototype.toFixed10 = function(precision) {
        return Math.round10(this, -precision).toFixed(precision);
    
  2. toFixedBtoFixed ( precision )
    Number.prototype.toFixedB = function toFixed ( precision ) {
        var multiplier = Math.pow( 10, precision + 1 ),
            wholeNumber = Math.floor( this * multiplier );
        return (Math.round( wholeNumber / 10 ) * 10 / multiplier).toFixed(precision);
    
  3. toFixedDown(digits)
    Number.prototype.toFixedDown = function(digits) {
        var n = this - Math.pow(10, -digits)/2;
        n += n / Math.pow(2, 53); 
        return n.toFixed(digits);
    
  4. 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();
    };
    
  5. toFixedtoFixed
    function toFixed(num){
      var divisor = parseInt(1 + "0".repeat(num));
      return Math.round(this*divisor)/divisor
    Number.prototype.toFixed = toFixed
    
  6. toNumFixed(num)
    Number.prototype.toNumFixed = function (num) {
      return parseFloat(this.toFixed(num));
    
  7. 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;
    };
    
  8. to2Digits()
    Number.prototype.to2Digits = function () {
       return this.toFixed(2).toString().replace(".", ",");
    };