mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 14:44:15 +00:00
feat: astro test
This commit is contained in:
parent
df6e31ba89
commit
84144c383c
262 changed files with 18993 additions and 2655 deletions
11
frontend/src/lib/abbreviation.ts
Normal file
11
frontend/src/lib/abbreviation.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
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
|
||||
// update: it went into thousands
|
||||
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