Advertisement
Exhabition

Bytes converter

Oct 2nd, 2020 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (bytes === 0) return '0 Bytes';
  2. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  3. const i = Math.floor(Math.log(bytes) / Math.log(1024));
  4. return `${parseFloat((bytes / Math.pow(1024, i)).toFixed(2))} ${sizes[i]}`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement