README
number-comma-format
Install
npm install --save number-comma-format
or
yarn add number-comma-format
Usage
var numberFormat = require('number-comma-format')
numberFormat("-12.0000") // "-12"
numberFormat(120000) // "120,000"
numberFormat(-120000, 2) // "-120,000.00"
numberFormat(131277.092213, 2, 3) // "131,277.09"
numberFormat(131277.092213, 2, 3, "#") // "131#277.09"
numberFormat(131277.092213, 2, 3, "#","|") // "131#277|09"
const _bindWith = numberFormat.bindWith(2, 4, ",", ".")
_bindWith(131277.092213); // 13,1277.09
API
numberFormat(inputNumber, precision, digit, separator, decimalChar)
Parameters:
- inputNumber(required) : {(Number|String)} Number to format .
- optionalPrecision: {Number} precision for the decimal .
- optionalDigit: {Number} digits of the separator. default 3
- separator : {String} Value used to separate numbers. default ','
- decimalChar : {String} Value used to separate the decimal value. default '.'
Returns:
- {String} formatted number, if {inputNumber} is not a number or string, that will be that self
bindWith(precision, digit, separator, decimalChar)
The numberFormat
function accepts these same parameters as the second and third params. This prevents using currying to bind them and reuse that bound function.
The bindWith
function accepts the options and returns a function bound with them.
var numberFormat = require('number-comma-format')
const _bindWith = numberFormat.bindWith(2, 4, ",", ".")
_bindWith(131277.092213); // 13,1277.09