# components/numbers (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/numbers.ts](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts).

## Functions

### `isCompact`

Function.

`text` is a short number: it ends with a compact suffix.

```ts
function isCompact(text: string): boolean
```

**Parameters**

- `text` (`string`): The formatted number.

**Returns** `boolean`

Source: [ui/src/components/numbers.ts:171](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L171)

### `numberFormats`

Function.

The number formats of `locale`, made once per locale.

```ts
function numberFormats(locale?: string): NumberFormats
```

**Parameters**

- `locale?` (`string`, default `'en-US'`): A BCP 47 locale. Default `en-US`.

**Returns** `NumberFormats`

Source: [ui/src/components/numbers.ts:34](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L34)

### `setDecimals`

Function.

One decimal count for a set of values (a column, a series, a stat row,
NU5): the fewest, up to `max`, that write every value as given, so no
value is rounded away from the data, no non-zero value reads as zero and
no two different values read the same.

```ts
function setDecimals(values: readonly number[], max?: number): number
```

**Parameters**

- `values` (`readonly number[]`): The set.
- `max?` (`number`, default `2`): The most decimals to use.

**Returns** `number`

Source: [ui/src/components/numbers.ts:92](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L92)

### `shareDecimals`

Function.

The decimals of a list of shares (0 to 1), one count for all: 1 when any
share is under 10%, else 0.

```ts
function shareDecimals(shares: readonly number[]): number
```

**Parameters**

- `shares` (`readonly number[]`): The shares.

**Returns** `number`

Source: [ui/src/components/numbers.ts:127](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L127)

### `trueMinus`

Function.

A value's minus sign as U+2212, the one a reader sees as a minus, when the
text starts with a hyphen before a digit (`-52%` to `−52%`).

```ts
function trueMinus(text: string): string
```

**Parameters**

- `text` (`string`): A formatted value.

**Returns** `string`

Source: [ui/src/components/numbers.ts:137](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L137)

### `unitDecimals`

Function.

[`setDecimals`](https://zidane.si/docs/reference/ui-components-numbers.md#setDecimals) for a set in `unit`: money takes 0 or 2 decimals, never 1 (`$190.50`).

```ts
function unitDecimals(values: readonly number[], unit: string | undefined): number
```

**Parameters**

- `values` (`readonly number[]`): The set.
- `unit` (`string | undefined`): The values' unit.

**Returns** `number`

Source: [ui/src/components/numbers.ts:116](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L116)

### `withUnit`

Function.

A formatted number with its unit, by one rule: currency symbols go before
the number (`$12`, `-$3`), percent signs stick to it (`12%`), any
other unit follows after a space that never breaks (`1,882 ms`), a
thin one after a short number (`1.5k ms`).

```ts
function withUnit(text: string, unit: string | undefined, compact?: boolean): string
```

**Parameters**

- `text` (`string`): The formatted number.
- `unit` (`string | undefined`): The unit, or nothing.
- `compact?` (`boolean`, default `false`): `text` is a short number (`1.5k`).

**Returns** `string`

Source: [ui/src/components/numbers.ts:154](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L154)

## Interfaces

### `NumberFormats`

Interface.

The formats of one locale.

```ts
interface NumberFormats
```

**Properties**

- `compact` (`(value: number) => string`): A short number with at most 3 significant digits: `950`, `1.5k`, `48.2k`, `4.81M`, `2B`.
- `locale` (`string`): The locale the numbers are written in.
- `number` (`(value: number, digits?: number, fixed?: boolean) => string`): A grouped number: `1,234.5`. At most `digits` decimals (default 2), exactly `digits` with `fixed`.
- `percent` (`(value: number, digits?: number, fixed?: boolean) => string`): A share as a percent: `0.123` is `12.3%`. At most `digits` decimals (default 1), exactly `digits` with `fixed`.

Source: [ui/src/components/numbers.ts:9](https://github.com/Tahul/zidane/blob/main/ui/src/components/numbers.ts#L9)
