﻿function CalculateSizeValue(sizeInBytes) {
    var results = "0 Bytes";
    if (sizeInBytes > 0) {
        if (sizeInBytes >= Math.pow(1024, 8)) {
            //Yottabyte
            results = sizeInBytes / Math.pow(1024, 8);
            results = results.toFixed(2) + " YB";
        }
        else if (sizeInBytes >= Math.pow(1024, 7)) {
            //Zettabyte
            results = sizeInBytes / Math.pow(1024, 7);
            results = results.toFixed(2) + " ZB";
        }
        else if (sizeInBytes >= Math.pow(1024, 6)) {
            //Exabyte
            results = sizeInBytes / Math.pow(1024, 6);
            results = results.toFixed(2) + " EB";
        }
        else if (sizeInBytes >= Math.pow(1024, 5)) {
            //Pedtabyte
            results = sizeInBytes / Math.pow(1024, 5);
            results = results.toFixed(2) + " PB";
        }
        else if (sizeInBytes >= Math.pow(1024, 4)) {
            //Terabyte
            results = sizeInBytes / Math.pow(1024, 4);
            results = results.toFixed(2) + " TB";
        }
        else if (sizeInBytes >= Math.pow(1024, 3)) {
            //Gigabyte
            results = sizeInBytes / Math.pow(1024, 3);
            results = results.toFixed(2) + " GB";
        }
        else if (sizeInBytes >= Math.pow(1024, 2)) {
            //Megabyte
            results = sizeInBytes / Math.pow(1024, 2);
            results = results.toFixed(2) + " MB";
        }
        else if (sizeInBytes >= Math.pow(1024, 1)) {
            //Kilobyte
            results = sizeInBytes / Math.pow(1024, 1);
            results = results.toFixed(2) + " KB";
        }
        else if (sizeInBytes < 1024) {
            //Byte
            results = sizeInBytes;
            results = results.toFixed(0) + " BY";
        }
    }

    return results;
}
