diff --git a/bignumber.js b/bignumber.js index ecf03bd..017265b 100644 --- a/bignumber.js +++ b/bignumber.js @@ -2765,7 +2765,8 @@ function clone(configObject) { fractionPart = arr[1], len = intPart.length; - if (g2) { + // A groupSize of 0 disables grouping, regardless of secondaryGroupSize. + if (g1 > 0 && g2) { i = g1; g1 = g2; g2 = i; diff --git a/test/methods/toFormat.js b/test/methods/toFormat.js index 90d5d0f..0776952 100644 --- a/test/methods/toFormat.js +++ b/test/methods/toFormat.js @@ -279,6 +279,18 @@ Test('toFormat', function () { restoreDefaultFormat(); + // groupSize: 0 must disable grouping even when secondaryGroupSize is set, + // instead of falling back to grouping by secondaryGroupSize alone. + + BigNumber.config({ FORMAT: { groupSize: 0, secondaryGroupSize: 2 }}); + + t('123456789', 123456789); + t('1234.56', '1234.56'); + t('-9.91', '-9.91'); + t('1000037.123', '1000037.123456789', 3); + + restoreDefaultFormat(); + //if (typeof window == 'undefined') { // var vm = require('vm'); // t('1,234.57', '1234.567', vm.runInNewContext('[2, 2]'));