Implement compression quota refunds and admin manual subscription
This commit is contained in:
23
frontend/src/utils/format.ts
Normal file
23
frontend/src/utils/format.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (!Number.isFinite(bytes) || bytes <= 0) return '0 B'
|
||||
const units = ['B', 'KB', 'MB', 'GB']
|
||||
let value = bytes
|
||||
let unit = 0
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024
|
||||
unit += 1
|
||||
}
|
||||
const digits = unit === 0 ? 0 : unit === 1 ? 1 : 2
|
||||
return `${value.toFixed(digits)} ${units[unit]}`
|
||||
}
|
||||
|
||||
export function formatCents(amountCents: number, currency: string): string {
|
||||
const amount = (amountCents ?? 0) / 100
|
||||
const cc = (currency ?? 'CNY').toUpperCase()
|
||||
return new Intl.NumberFormat('zh-CN', {
|
||||
style: 'currency',
|
||||
currency: cc,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(amount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user