const units = ['B', 'KB', 'MB', 'G', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let value = parseFloat(data);
if (isNaN(value)) return null;
let unit = data.replace(/[\d.]/g, '').toUpperCase();
let index = units.indexOf(unit);
if (index < 0) {
return null;
}
return value * Math.pow(1024, index);
js将KB GB等单位转换成B
最新推荐文章于 2024-10-16 16:26:58 发布