esamattis / esamattis/underscore.string
_.numberFormat not support the number is a float.
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
the _.numberFormat not support the number is a float.
example:
var tmpNumber = 10000.123;
_.numberFormat(tmpNumber )
it println: 10,000
i want it output 10,000.123
when we use this function, i don't care the number of variable "tmpNumber" is an int or float , also i don't want it output an int string. I only hope it format the int part of variable "tmpNumber", I want the output is the "10,000.123"
but now this function not support this. i modify the function used in my app.
on below :
```
numberFormat : function(number, dec, dsep, tsep) {
if (isNaN(number) || number == null) return '';
//begin: modify here
if(!isNaN(parseInt(dec,10))){
number = number.toFixed(~~dec);
}else{
number = number.toString();
}
//end
tsep = typeof tsep == 'string' ? tsep : ',';
var parts = number.split('.'), fnums = parts[0],
decimals = parts[1] ? (dsep || '.') + parts[1] : '';
return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals;
},
```
Contributor guide
Assessment
This issue has not been assessed yet.