fix: use IEC units for binary sizes (#2901)

This commit is contained in:
3gf8jv4dv
2026-07-09 09:40:19 +08:00
committed by GitHub
parent f3fbbb3720
commit c0dd64c71c
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ function fm(value) {
exports.sizeFormate = size => { exports.sizeFormate = size => {
// https://gist.github.com/thomseddon/3511330 // https://gist.github.com/thomseddon/3511330
if (!size) return '0 b' if (!size) return '0 b'
let units = ['b', 'kB', 'MB', 'GB', 'TB'] let units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
let number = Math.floor(Math.log(size) / Math.log(1024)) let number = Math.floor(Math.log(size) / Math.log(1024))
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}` return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
} }
+1 -1
View File
@@ -12,7 +12,7 @@ export const getRandom = (min: number, max: number): number => Math.floor(Math.r
export const sizeFormate = (size: number): string => { export const sizeFormate = (size: number): string => {
// https://gist.github.com/thomseddon/3511330 // https://gist.github.com/thomseddon/3511330
if (!size) return '0 B' if (!size) return '0 B'
let units = ['B', 'KB', 'MB', 'GB', 'TB'] let units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
let number = Math.floor(Math.log(size) / Math.log(1024)) let number = Math.floor(Math.log(size) / Math.log(1024))
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}` return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
} }