feat(format): add locales support to number formatting
This commit is contained in:
Vendored
+10
-4
@@ -27,16 +27,22 @@ import {
|
||||
// Number Formatting
|
||||
// ============================================================================
|
||||
|
||||
export function formatNumber(value: number | null | undefined): string {
|
||||
export function formatNumber(
|
||||
value: number | null | undefined,
|
||||
locales?: Intl.LocalesArgument
|
||||
): string {
|
||||
if (value == null || Number.isNaN(value as number)) return '-'
|
||||
return Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }).format(
|
||||
return Intl.NumberFormat(locales, { maximumFractionDigits: 2 }).format(
|
||||
value as number
|
||||
)
|
||||
}
|
||||
|
||||
export function formatCompactNumber(value: number | null | undefined): string {
|
||||
export function formatCompactNumber(
|
||||
value: number | null | undefined,
|
||||
locales?: Intl.LocalesArgument
|
||||
): string {
|
||||
if (value == null || Number.isNaN(value as number)) return '-'
|
||||
return Intl.NumberFormat(undefined, {
|
||||
return Intl.NumberFormat(locales, {
|
||||
notation: 'compact',
|
||||
maximumFractionDigits: 1,
|
||||
}).format(value as number)
|
||||
|
||||
Reference in New Issue
Block a user