mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 06:34:15 +00:00
feat: abbreviate likes in mii list component
This commit is contained in:
parent
6b1cfff9c6
commit
75bd7281e4
3 changed files with 16 additions and 4 deletions
10
src/lib/abbreviation.ts
Normal file
10
src/lib/abbreviation.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export function abbreviateNumber(number: number): string {
|
||||
if (number < 1000) return number.toString();
|
||||
|
||||
const units = ["", "K", "M", "B", "T"]; // very unlikely to go into thousands, let alone millions, but you never know
|
||||
const order = Math.floor(Math.log10(number) / 3);
|
||||
const unit = units[order] || "";
|
||||
const scaled = number / Math.pow(10, order * 3);
|
||||
|
||||
return `${scaled.toFixed(scaled < 10 ? 1 : 0)}${unit}`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue