相关疑难解决方法(0)

在JavaScript中将大小(以字节为单位)转换为KB,MB,GB的正确方法

我得到这个代码通过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)

javascript byte converters

216
推荐指数
10
解决办法
23万
查看次数

标签 统计

byte ×1

converters ×1

javascript ×1