Version: v0.8.0 - Beta.  We welcome contributors & feedback.

Number.format

format($options={}) -> string

Description

Format the number as a string.

Decimal digits are rounded.

$num = 1234.56

$num.format()
//= '1,235'

$num.format({ numDecimals: 1 })
//= '1,234.6'

$num.format({ numDecimals: 2, thousandsSep: '' })
//= '1234.56'

$num.format({ thousandsSep: '.', decimalSep: ',' })
//= '1.234,56'

$num.format({ sign: true })
//= '+1,235'

Options

Option Value Description
sign true/false Append the value’s sign + if positive. (Default: false)
parens true/false Use parens to indicate negative value. (Default: false)
zeroSign + or - Treat zero as positive + or negative -. (Default: none)
numDecimals number Number of digits after the decimal separator. (Default: 0)
thousandSep string String character to separate thousands. (Default: comma ,)
decimalSep string String character to separate decimal digits. (Default: period .)

See Also