Skip to content

formatNumber

Formats a number with a fixed number of fraction digits using Intl.NumberFormat. Use it to keep numeric precision consistent across tables, cards, and chart labels.

Importing

ts
import { formatNumber } from '@almighty-shogun/utils'

Usage

ts
import { formatNumber } from '@almighty-shogun/utils'

const amount = formatNumber(1234.567, 2, 'en');

Parameters

value: number
Value to format.

decimals: number
Fraction digits.
Default: 2

locale?: string
Locale override.

Returns

A localized number string with exactly decimals fraction digits. This is useful when table columns need visually consistent precision.

Type signature

ts
declare function formatNumber(
    value: number,
    decimals: number,
    locale?: string
): string;

All packages are released under the MIT License.