Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

kb to mb javascript

const 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"];
    const i = Math.floor(Math.log(bytes) / Math.log(k));

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

kb to mb js

const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

function niceBytes(x){

  let l = 0, n = parseInt(x, 10) || 0;

  while(n >= 1024 && ++l){
      n = n/1024;
  }
  //include a decimal point and a tenths-place digit if presenting 
  //less than ten of KB or greater units
  return(n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}
Comment

convert bytes to kb or mb javascript

format bytes size
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to change checkbox state in jquery 
Javascript :: simple reactjs login form 
Javascript :: sh: 1: react-scripts: not found 
Javascript :: get n number of elements from array javascript 
Javascript :: javascript remove last element from array 
Javascript :: how to get element of an array in javascript 
Javascript :: check all values from keys in object js 
Javascript :: how to go back to previous page after updating data in jquery 
Javascript :: import fetch from ("node-fetch"); ^^^^^^ SyntaxError: Cannot use import statement outside a module 
Javascript :: js refresh iframe 
Javascript :: access to model from js 
Javascript :: convert iso string to datetime javascript 
Javascript :: array chaing in js 
Javascript :: js generate random color 
Javascript :: Putting password in a zip file using node.js 
Javascript :: Two different lockfiles found: package-lock.json and yarn.lock 
Javascript :: js get json keys 
Javascript :: datatables add row 
Javascript :: node js to int 
Javascript :: prettier/prettier in react 
Javascript :: redux dev tools 
Javascript :: javascript remove underscore and capitalize 
Javascript :: javascript return promise 
Javascript :: Without using a new array or the reverse() method to Reverse an Array 
Javascript :: python iterate json file 
Javascript :: jquery find previous element with class 
Javascript :: enter only numbers in input field angular 
Javascript :: how to include a css file in jsp 
Javascript :: array of objects to array 
Javascript :: diff two arrays javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =