Skip to content

Modules: Number

Alex Bruno Cáceres edited this page Mar 2, 2023 · 3 revisions

Useful methods to deal with numbers.

numberFormat

Formats a given number to a localized string.

It requires two arguments: number and locale. You can also pass in a third argument to set up the decimal length.

import { numberFormat } from '@jsweb/utils/modules/number'

const number = 1234567.89
const br = numberFormat(number, 'pt-BR') // 1.234.568
const en = numberFormat(number, 'en-US') // 1,234,568
const fr = numberFormat(number, 'fr-FR') // 1 234 568
const decimals = numberFormat(number, 'pt-BR', 2) // 1.234.567,89

Clone this wiki locally