在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ js里面有現(xiàn)成的庫(kù)函數(shù)用來(lái)做內(nèi)存單位轉(zhuǎn)換么?給個(gè)數(shù)字轉(zhuǎn)成KB/MB/GB/TB

js里面有現(xiàn)成的庫(kù)函數(shù)用來(lái)做內(nèi)存單位轉(zhuǎn)換么?給個(gè)數(shù)字轉(zhuǎn)成KB/MB/GB/TB

js里面有現(xiàn)成的庫(kù)函數(shù)用來(lái)做內(nèi)存單位轉(zhuǎn)換么?給個(gè)數(shù)字轉(zhuǎn)成KB/MB/GB/TB

回答
編輯回答
下墜

自己寫一個(gè)吧

2018年6月25日 19:01
編輯回答
枕邊人

自己寫一個(gè)吧,字節(jié)數(shù)轉(zhuǎn)為kb/mb/gb/tb
//文件大小從字節(jié)數(shù)格式化為kb,mb,gb,tb 精確到一位小數(shù),小于0.1kb的轉(zhuǎn)為0

const formatFileSize = size => {
  const scale = 1000
  const digitList = ['K', 'M', 'G', 'T']
  let residue = Math.round(size%scale/100)//小數(shù)點(diǎn)后數(shù),1位
  let _integer = Math.round(size/scale) //最小單位kb
  let digit = 0
  while(_integer > scale) {
    residue = Math.round(_integer%scale/100)
    _integer = Math.round(_integer/scale)
    digit++
  }
  return `${_integer}.${residue}${digitList[digit]}B`
}
2017年7月10日 00:41