mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(web): stop formatUsageNumber rendering 1000.0K at unit boundaries (#1340)
Co-authored-by: Vedant Mahajan <vedant.04.mahajan@gmail.com>
This commit is contained in:
parent
47152afc1d
commit
00e57fb9c2
1 changed files with 11 additions and 3 deletions
|
|
@ -185,18 +185,26 @@ export function getBrainTrialInfo(
|
|||
}
|
||||
|
||||
/**
|
||||
* Format a number with K/M suffix for display
|
||||
* Format a number with K/M/B suffix for display
|
||||
* @example formatUsageNumber(1500000) => "1.5M"
|
||||
* @example formatUsageNumber(50000) => "50K"
|
||||
* @example formatUsageNumber(999950) => "1.0M"
|
||||
*/
|
||||
export function formatUsageNumber(value: number): string {
|
||||
const withSuffix = (n: number, suffix: string) =>
|
||||
n % 1 === 0 ? `${n}${suffix}` : `${n.toFixed(1)}${suffix}`
|
||||
|
||||
if (value >= 1_000_000) {
|
||||
const millions = value / 1_000_000
|
||||
return millions % 1 === 0 ? `${millions}M` : `${millions.toFixed(1)}M`
|
||||
return millions >= 999.95
|
||||
? withSuffix(value / 1_000_000_000, "B")
|
||||
: withSuffix(millions, "M")
|
||||
}
|
||||
if (value >= 1_000) {
|
||||
const thousands = value / 1_000
|
||||
return thousands % 1 === 0 ? `${thousands}K` : `${thousands.toFixed(1)}K`
|
||||
return thousands >= 999.95
|
||||
? withSuffix(value / 1_000_000, "M")
|
||||
: withSuffix(thousands, "K")
|
||||
}
|
||||
return value.toString()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue