mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
19 lines
419 B
TypeScript
19 lines
419 B
TypeScript
export const formatTokens = (tokens: number | null | undefined, decimals = 0) => {
|
|
if (tokens === null || tokens === undefined) {
|
|
return "-"
|
|
}
|
|
|
|
if (tokens < 1000) {
|
|
return tokens.toString()
|
|
}
|
|
|
|
if (tokens < 1000000) {
|
|
return `${(tokens / 1000).toFixed(decimals)}K`
|
|
}
|
|
|
|
if (tokens < 1000000000) {
|
|
return `${(tokens / 1000000).toFixed(decimals)}M`
|
|
}
|
|
|
|
return `${(tokens / 1000000000).toFixed(decimals)}B`
|
|
}
|