Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript function convert bytes into mb

function bytesToSize(bytes) {
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
  if (bytes === 0) return 'n/a'
  const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
  if (i === 0) return `${bytes} ${sizes[i]})`
  return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
}
Comment

byte to mb js

function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}
Comment

js mb to bytes

function toBytes(size, type)
{
  const types = ["B", "KB", "MB", "GB", "TB"];

  const key = types.indexOf(type.toUpperCase())
  
  if (typeof key !== "boolean") {
      return  size * 1024 ** key;
  }
  return "invalid type: type must be GB/KB/MB etc.";
}
Comment

convert bytes to kb or mb javascript

format bytes size
Comment

PREVIOUS NEXT
Code Example
Javascript :: round innerhtml up 
Javascript :: status code json 
Javascript :: print object keys 
Javascript :: javascript size array 
Javascript :: sweetalert allow html 
Javascript :: javascript cheat sheet pdf 
Javascript :: xpath nodejs 
Javascript :: class component react js 
Javascript :: fullcalendar angular add events 
Javascript :: in text includes in aray of objects 
Javascript :: express add delay 
Javascript :: auto import vscode not working 
Javascript :: js array.prototype.join 
Javascript :: javascript add element to array 
Javascript :: date format french js 
Javascript :: cards in react native 
Javascript :: nodejs express server img src 
Javascript :: jquery find tag and class 
Javascript :: angular remove index of array 
Javascript :: js input trigger oninput event 
Javascript :: async await promise all javascript 
Javascript :: how to get all attributes of an element in jquery 
Javascript :: draw border on canvas 
Javascript :: js push in object 
Javascript :: crud template 
Javascript :: timeline javascript 
Javascript :: mongoose find multiple values one query 
Javascript :: multiple checkbox validation in jquery 
Javascript :: javascript promise 
Javascript :: reset form jquery 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =