Skip to content

Number words

Figures, counts, file sizes, medians and percents written the same way on every site.

API

Functions

FunctionSignatureDoes
formatBytes(bytes: number): stringA file size. Binary division (1 kB is 1,024 bytes), as Windows states a size and as every copy in the network already did, so no size a site shows changes. Bytes and kB are whole; MB and up keep one decimal under 100 and drop a trailing ".0" ("2 MB", "2.4 MB", "512 MB").
shortCount(n: number): stringA count where the room is small (a tile, a chip): exact under 10,000 ("9,999"), then short with at most one decimal ("12K", "1.2M"). The exact figure belongs in the accessible name or a title beside it whenever the short one stands in for it.
median(values: readonly number[], options?: { round?: boolean | undefined; }): number | nullThe middle value, or the mean of the two middle values for an even count. Null for no values, never NaN. round: true rounds the result (whole minutes, whole milliseconds). The caller's array is not changed.
percentOf(part: number, whole: number, options?: PercentOptions): number | nullpart / whole as a percent number, rounded to digits places. Null when the whole is 0 or less, or either is not a number: a rate of nothing is no data, never 0%.
formatPercent(value: number, options?: PercentOptions): stringA percent number as text: "12%", "12.5%". digits fixes the places ("20.0%"); without it a whole number has none and anything else keeps what it has.
formatBps(bps: number, options?: PercentOptions): stringBasis points as a percent: 2000 bps is "20%", 125 is "1.25%". digits fixes the places.