@serenity-is/corelib / formatNumber
Function: formatNumber()
formatNumber(
num,format?,decOrLoc?,grp?):string
Defined in: src/base/formatting.ts:337
Formats a number using .NET-style numeric format strings and locale settings.
Parameters
num
number
Value to format; null / undefined yields "" and NaN yields nanSymbol.
format?
string
Format specifier. "g" (general), "d"/"x"/"e"/"f"/"n"/"c"/"p", or a custom pattern ("#,##0.00", "000", etc.).
decOrLoc?
Either a Locale / NumberFormat object, or the decimal separator string for a lightweight inline locale.
string | NumberFormat
grp?
string
Group separator when decOrLoc is a decimal-separator string. Ignored otherwise.
Returns
string
The formatted number string, applying grouping, decimal separator, and locale symbols from decOrLoc or Culture.
Default Value
"g".
Remarks
"n"/"N"insert grouping;"c"/"p"appendcurrencySymbol/percentSymbol(percent multiplies by 100).- Custom patterns quote literals with
'and escape with ``.
Example
formatNumber(1234.5, "n2"); // e.g. "1,234.50" depending on Culture
formatNumber(0.42, "p0"); // e.g. "42%"