fix(localize): update the way to obtain the group separator for a number

four digit numbers can be written without separator, so it would be
safer to obtain the separator by formatting a five digit number. The bug
was found with the locale 'es-ES', where the format returned for '1000'
was '1000' instead of the expected '1.000'. We add the specific expect
clause on the test for it.

 On branch fix/numberGroupSeparator
 Changes to be committed:
	modified:   packages/localize/src/number/getGroupSeparator.js
	modified:   packages/localize/test/number/getGroupSeparator.test.js
This commit is contained in:
Jose C Perea 2019-08-13 18:57:27 +02:00
parent 2bf8c07079
commit b0d6f496f8
2 changed files with 3 additions and 2 deletions

View file

@ -12,6 +12,6 @@ export function getGroupSeparator(locale) {
const formattedNumber = Intl.NumberFormat(computedLocale, { const formattedNumber = Intl.NumberFormat(computedLocale, {
style: 'decimal', style: 'decimal',
minimumFractionDigits: 0, minimumFractionDigits: 0,
}).format('1000'); }).format('10000');
return normalSpaces(formattedNumber[1]); return normalSpaces(formattedNumber[2]);
} }

View file

@ -7,5 +7,6 @@ describe('getGroupSeparator', () => {
expect(getGroupSeparator('en-GB')).to.equal(','); expect(getGroupSeparator('en-GB')).to.equal(',');
expect(getGroupSeparator('nl-NL')).to.equal('.'); expect(getGroupSeparator('nl-NL')).to.equal('.');
expect(getGroupSeparator('fr-FR')).to.equal(' '); expect(getGroupSeparator('fr-FR')).to.equal(' ');
expect(getGroupSeparator('es-ES')).to.equal('.');
}); });
}); });