Skip to content
Sheetwrite

@sheetwrite/core/codec

formatNumberfunction

Report a problem

On this page

Deterministic Excel-style number/date formatter. Supports explicit locale separators, percent/scientific notation, UTC date/time tokens, four-section positive/negative/zero/text codes, fractions (# ?/?, # ??/16), quoted literals, and backslash escapes. General formats exactly like an omitted code, and so does the Text format @ for a number.

Declaration

function formatNumber(
value: number | string,
format?: string,
locale?: string,
): string

Parameters

value: number | stringrequired

The number to format; a string is placed into the code's text section.

format?: stringoptional

Excel number-format code, such as #,##0.00 or yyyy-mm-dd; when it is omitted, the value is formatted as with General.

locale?: stringoptional

BCP 47 locale for the decimal and group separators; defaults to en-US.

Returns

string

The value as Excel would show it with that code.

Referenced by

Public exports naming formatNumber