Questions tagged «human-readable»

17
将文件大小(以字节为单位)转换为可读字符串
我正在使用此功能将以字节为单位的文件大小转换为人类可读的文件大小: function getReadableFileSizeString(fileSizeInBytes) { var i = -1; var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; do { fileSizeInBytes = fileSizeInBytes / 1024; i++; } while (fileSizeInBytes > 1024); return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; }; 但是,这似乎不是100%准确的。例如: getReadableFileSizeString(1551859712); // output is "1.4 GB" 这不是"1.5 …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.