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 :: javascript detect enter press on input 
Javascript :: break camelcase codewars 
Javascript :: js change contenteditable value 
Javascript :: jquery post json example 
Javascript :: scoll a div to bottom in angular 
Javascript :: if is array javascript 
Javascript :: vue.js use scss in balise style 
Javascript :: disable autocomplete in react fields 
Javascript :: vibrate javascript 
Javascript :: remove word from string javascript 
Javascript :: split array into chunks 
Javascript :: js get mouseclick 
Javascript :: angular button open file input 
Javascript :: click element via javascript chrome inspector console 
Javascript :: js remove object from array by value 
Javascript :: ajax download file 
Javascript :: console.log formdata 
Javascript :: <scriptalert(document.domain)</script 
Javascript :: javascript remove element by id 
Javascript :: jquery show flex 
Javascript :: regex match everything before string 
Javascript :: create react native app 
Javascript :: javascript factorial 
Javascript :: sequelize order includes 
Javascript :: read only javascript 
Javascript :: delayed in js 
Javascript :: jquery scroll to id 
Javascript :: regex to extract valid http or https 
Javascript :: append option to select ajax javascript 
Javascript :: javascript modal close 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =