Bytes to Readable format (JavaScript)

function formatSize(v, c) {
    v = parseInt(v, 10);
    for(c = 0; v > 1024; c++) v = (v / 1024).toFixed(2);
    return v + ' ' + ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][c]

P.S.: This function converts size in bytes to a human readable format.

дядь Саша

hardcore javascript & php programmer, passionate reverse engineer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.