mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-15 04:18:16 +08:00
style: Update formatFileSize function to accept decimals parameter
This commit is contained in:
@@ -60,7 +60,7 @@ export const prefixWithPlus = (value: number) => (value > 0 ? `+${value}` : valu
|
||||
export const formatSeason = (value: string) => (value ? `S${value.padStart(2, '0')}` : '')
|
||||
|
||||
// 格式化为xx[TGMK]B
|
||||
export function formatFileSize(bytes: number) {
|
||||
export function formatFileSize(bytes: number, decimals = 2) {
|
||||
if (bytes < 0) throw new Error('字节数不能为负数。')
|
||||
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
@@ -72,7 +72,7 @@ export function formatFileSize(bytes: number) {
|
||||
unitIndex++
|
||||
}
|
||||
|
||||
return `${size.toFixed(2)} ${units[unitIndex]}`
|
||||
return `${size.toFixed(decimals)} ${units[unitIndex]}`
|
||||
}
|
||||
|
||||
// 将时间秒格式化为时分秒
|
||||
|
||||
Reference in New Issue
Block a user