我得到这个代码通过PHP来隐藏大小的字节数.
现在我想使用JavaScript 将这些大小转换为人类可读的大小.我试图将此代码转换为JavaScript,如下所示:
function formatSizeUnits(bytes){
if (bytes >= 1073741824) { bytes = (bytes / 1073741824).toFixed(2) + " GB"; }
else if (bytes >= 1048576) { bytes = (bytes / 1048576).toFixed(2) + " MB"; }
else if (bytes >= 1024) { bytes = (bytes / 1024).toFixed(2) + " KB"; }
else if (bytes > 1) { bytes = bytes + " bytes"; }
else if (bytes == 1) { bytes = bytes + " byte"; }
else …
Run Code Online (Sandbox Code Playgroud)