JS – konwersja B na KB, MB, GB, TB,…

Przelicza bajty na wielokrotności

let nBytes = 22323848499494949494;
let sOutput = nBytes + " bytes";

const aMultiples = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];

for (nMultiple = 0, nApprox = nBytes / 1024; nApprox > 1; nApprox /= 1024, nMultiple++) {
    sOutput = nApprox.toFixed(3) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
}