Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/utils/numbers.ts
1006 views
1
import { defaultLocale } from "../data/locales"
2
3
export const formatNumber = (
4
number: number,
5
localeCode: string = defaultLocale,
6
options: Intl.NumberFormatOptions = {}
7
): string => {
8
let intlOptions: Intl.NumberFormatOptions = {
9
notation: "compact",
10
...options,
11
}
12
return new Intl.NumberFormat(localeCode, intlOptions).format(number)
13
}
14
15
export const percIncrease = (a: number, b: number): number => {
16
let percent
17
18
if (b !== 0) {
19
if (a !== 0) {
20
percent = (b - a) / a
21
} else {
22
percent = 1
23
}
24
} else if (b === 0 && a === 0) {
25
percent = 0
26
} else {
27
percent = -1
28
}
29
30
return percent
31
}
32
33