@@ -581,15 +581,21 @@ lib.objectFromPath = function(path, value) {
581
581
* // returns '2016'
582
582
*
583
583
* @example
584
+ * lib.numSeparate(3000, '.,', true);
585
+ * // returns '3,000'
586
+ *
587
+ * @example
584
588
* lib.numSeparate(1234.56, '|,')
585
589
* // returns '1,234|56'
586
590
*
587
591
* @param {string|number } value the value to be converted
588
592
* @param {string } separators string of decimal, then thousands separators
593
+ * @param {boolean } separatethousands boolean, 4-digit integers are separated if true
589
594
*
590
595
* @return {string } the value that has been separated
591
596
*/
592
- lib . numSeparate = function ( value , separators ) {
597
+ lib . numSeparate = function ( value , separators , separatethousands ) {
598
+ if ( ! separatethousands ) separatethousands = false ;
593
599
594
600
if ( typeof separators !== 'string' || separators . length === 0 ) {
595
601
throw new Error ( 'Separator string required for formatting!' ) ;
@@ -608,7 +614,7 @@ lib.numSeparate = function(value, separators) {
608
614
x2 = x . length > 1 ? decimalSep + x [ 1 ] : '' ;
609
615
610
616
// Years are ignored for thousands separators
611
- if ( thouSep && ( x . length > 1 || x1 . length > 4 ) ) {
617
+ if ( thouSep && ( x . length > 1 || x1 . length > 4 || separatethousands ) ) {
612
618
while ( thousandsRe . test ( x1 ) ) {
613
619
x1 = x1 . replace ( thousandsRe , '$1' + thouSep + '$2' ) ;
614
620
}
0 commit comments