formatNumber() Helper Method
The formatNumber() Helper Method module provides a helper function that returns it's passed argument as a formatted number using JavaScript's Intl.NumberFormat() API/method.
Import
To import the formatNumber() Helper Method:
javascript
import { formatNumber } from '@obewds/vueventus'
Arguments
Returns: String
Args | Type | Status | Description |
---|---|---|---|
number | Number | Required | A number to format as a human readable number string (with thousandths separators etc.) |
Use Example
javascript
console.log( formatNumber(123456) )
// returns (string): '123,456'
console.log( formatNumber(123456789) )
// returns (string): '123,456,789'
console.log( formatNumber(123456.1234) )
// returns (string): '123,456.123'
Module Code
ts
// ./src/helpers/formatNumber.ts
export default function (number: number): string {
return new Intl.NumberFormat().format(number)
}