Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS
vanillajs-helpers > “formatNumber”
► formatNumber(num: number
, settings?: FormatNumberSettings): string
Defined in formatNumber.ts:37
Formats a number with defined thousand and decimal separator, and a decimal limit (see limitDecimals
for details on decCount
)
// Default format
formatNumber(123456); // -> 123.456,00
// Custom format
formatNumber(123456, { decimals: '>3', thousandSep: '-', decimalSep: ':' }); // -> 123-456:000
Parameters:
Param | Type | Description |
---|---|---|
num | number |
Number to format |
settings | FormatNumberSettings | Settings for the number formatting |
Returns: string
Formatted number as a string
● decimalSep: string
= “,”
Defined in formatNumber.ts:16
● decimals: number
= 2
Defined in formatNumber.ts:14
● thousandSep: string
= “.”
Defined in formatNumber.ts:15