Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascrpt formatBytes

function formatBytes(bytes, decimals = 2) {
    if (bytes === 0) return '0 Bytes';

    const k = 1024;
    const dm = decimals < 0 ? 0 : decimals;
    const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

    const i = Math.floor(Math.log(bytes) / Math.log(k));

    return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
Comment

javascrpt formatBytes

function niceBytes(x){
 const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  let l = 0, n = parseInt(x, 10) || 0;
  while(n >= 1024 && ++l){
      n = n/1024;
  }
  return(n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: unload in jquery 
Javascript :: fullcalendar v5 time format am/pm 
Javascript :: Checking Empty JS Object 
Javascript :: jquery event keycode 
Javascript :: how do you make a random array in javascript 
Javascript :: javascript remove certain element from array 
Javascript :: js random in range 
Javascript :: vue watch child property 
Javascript :: js json stringfy beutify 
Javascript :: discord.js verify 
Javascript :: get form data in react 
Javascript :: mat checkbox change event in angular 7 
Javascript :: rounding to nearest hundredth js 
Javascript :: how to split text into array javascript 
Javascript :: remove property from object js 
Javascript :: push characters to a string javascript 
Javascript :: javascript get typeof array 
Javascript :: js get current timezone offset 
Javascript :: alphabet as array javascript 
Javascript :: cypress input value should be 
Javascript :: jquery window trigger resize 
Javascript :: package.json set environment variables 
Javascript :: javascript hashtag url 
Javascript :: Prevent Double Submit with JavaScript 
Javascript :: foreach reverse javascript 
Javascript :: owl carousel get started 
Javascript :: javascript constructor function vs factory function 
Javascript :: Fibonacci Series Program. in javascript 
Javascript :: javascript iterate over divs 
Javascript :: using map in useeffect 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =