mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-09 10:56:52 +08:00
Feat/apply free quota (#828)
Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
@@ -1,33 +1,36 @@
|
||||
/*
|
||||
* Formats a number with comma separators.
|
||||
* Formats a number with comma separators.
|
||||
formatNumber(1234567) will return '1,234,567'
|
||||
formatNumber(1234567.89) will return '1,234,567.89'
|
||||
*/
|
||||
export const formatNumber = (num: number | string) => {
|
||||
if (!num) return num;
|
||||
let parts = num.toString().split(".");
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
return parts.join(".");
|
||||
if (!num)
|
||||
return num
|
||||
const parts = num.toString().split('.')
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
return parts.join('.')
|
||||
}
|
||||
|
||||
export const formatFileSize = (num: number) => {
|
||||
if (!num) return num;
|
||||
const units = ['', 'K', 'M', 'G', 'T', 'P'];
|
||||
let index = 0;
|
||||
if (!num)
|
||||
return num
|
||||
const units = ['', 'K', 'M', 'G', 'T', 'P']
|
||||
let index = 0
|
||||
while (num >= 1024 && index < units.length) {
|
||||
num = num / 1024;
|
||||
index++;
|
||||
num = num / 1024
|
||||
index++
|
||||
}
|
||||
return num.toFixed(2) + `${units[index]}B`;
|
||||
return `${num.toFixed(2)}${units[index]}B`
|
||||
}
|
||||
|
||||
export const formatTime = (num: number) => {
|
||||
if (!num) return num;
|
||||
const units = ['sec', 'min', 'h'];
|
||||
let index = 0;
|
||||
if (!num)
|
||||
return num
|
||||
const units = ['sec', 'min', 'h']
|
||||
let index = 0
|
||||
while (num >= 60 && index < units.length) {
|
||||
num = num / 60;
|
||||
index++;
|
||||
num = num / 60
|
||||
index++
|
||||
}
|
||||
return `${num.toFixed(2)} ${units[index]}`;
|
||||
return `${num.toFixed(2)} ${units[index]}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user