Correct way to convert size in bytes to KB, MB, GB in JavaScript

I got this code to covert size in bytes via PHP. Now I want to convert those sizes to human readable sizes using JavaScript. I tried to convert this code to JavaScript, which looks like this: function formatSizeUnits(bytes){ if (bytes >= 1073741824) { bytes = (bytes / 1073741824).toFixed(2) + ” GB”; } else if (bytes … Read more