vanillajs-helpers

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS

View the Project on GitHub Tokimon/vanillajs-helpers

vanillajs-helpers > “formatNumber”

External module: “formatNumber”

Index

Interfaces

Functions

Object literals


Functions

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


Object literal: defaultSettings

decimalSep

● decimalSep: string = “,”

Defined in formatNumber.ts:16


decimals

● decimals: number = 2

Defined in formatNumber.ts:14


thousandSep

● thousandSep: string = “.”

Defined in formatNumber.ts:15