Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Modules: Number
Alex Bruno Cáceres edited this page Mar 3, 2023
·
3 revisions
Useful methods to deal with numbers.
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'constnumber=1234567.89constbr=numberFormat(number,'pt-BR')// 1.234.568consten=numberFormat(number,'en-US')// 1,234,568constfr=numberFormat(number,'fr-FR')// 1 234 568constdecimals=numberFormat(number,'pt-BR',2)// 1.234.567,89Formats a given number to a localized currency string.
It requires three arguments: number, locale, and currency. You can also pass in a fourth argument to set up the decimal length.
import{currencyFormat}from'@jsweb/utils/modules/number'constnumber=1234567.89constbr=currencyFormat(number,'pt-BR','BRL')// R$ 1.234.567,89consten=currencyFormat(number,'en-US','USD')// $1,234,567.89constfr=currencyFormat(number,'fr-FR','EUR')// 1 234 567,89 €Checks if a given number is between two other numbers (inclusive).
import{isBetween}from'@jsweb/utils/modules/number'constcheck=isBetween(256,128,512)// true