fix(localize): use option.locale to get separator in formatNumberToParts
This commit is contained in:
parent
169f0ef97e
commit
093cfa090a
2 changed files with 4 additions and 4 deletions
|
|
@ -61,7 +61,7 @@ export function formatNumberToParts(number, options) {
|
||||||
formattedParts.push({ type: 'integer', value: numberPart });
|
formattedParts.push({ type: 'integer', value: numberPart });
|
||||||
numberPart = '';
|
numberPart = '';
|
||||||
}
|
}
|
||||||
const decimal = getDecimalSeparator();
|
const decimal = getDecimalSeparator(computedLocale);
|
||||||
if (formattedNumber[i] === decimal) {
|
if (formattedNumber[i] === decimal) {
|
||||||
formattedParts.push({ type: 'decimal', value: formattedNumber[i] });
|
formattedParts.push({ type: 'decimal', value: formattedNumber[i] });
|
||||||
fraction = true;
|
fraction = true;
|
||||||
|
|
@ -71,7 +71,7 @@ export function formatNumberToParts(number, options) {
|
||||||
}
|
}
|
||||||
// detect literals (empty spaces) or space group separator
|
// detect literals (empty spaces) or space group separator
|
||||||
if (regexSpace.test(formattedNumber[i])) {
|
if (regexSpace.test(formattedNumber[i])) {
|
||||||
const group = getGroupSeparator();
|
const group = getGroupSeparator(computedLocale);
|
||||||
const hasNumberPart = !!numberPart;
|
const hasNumberPart = !!numberPart;
|
||||||
// Write number grouping
|
// Write number grouping
|
||||||
if (numberPart && !fraction) {
|
if (numberPart && !fraction) {
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ describe('formatNumberToParts', () => {
|
||||||
|
|
||||||
specs.forEach(([locale, currency, amount, expectedResult]) => {
|
specs.forEach(([locale, currency, amount, expectedResult]) => {
|
||||||
it(`formats ${locale} ${currency} ${amount} as "${stringifyParts(expectedResult)}"`, () => {
|
it(`formats ${locale} ${currency} ${amount} as "${stringifyParts(expectedResult)}"`, () => {
|
||||||
localize.locale = locale;
|
|
||||||
expect(
|
expect(
|
||||||
formatNumberToParts(amount, {
|
formatNumberToParts(amount, {
|
||||||
|
locale,
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
currency,
|
currency,
|
||||||
}),
|
}),
|
||||||
|
|
@ -60,9 +60,9 @@ describe('formatNumberToParts', () => {
|
||||||
|
|
||||||
specs.forEach(([locale, currency, amount, expectedResult]) => {
|
specs.forEach(([locale, currency, amount, expectedResult]) => {
|
||||||
it(`formats ${locale} ${currency} ${amount} as "${stringifyParts(expectedResult)}"`, () => {
|
it(`formats ${locale} ${currency} ${amount} as "${stringifyParts(expectedResult)}"`, () => {
|
||||||
localize.locale = locale;
|
|
||||||
expect(
|
expect(
|
||||||
formatNumberToParts(amount, {
|
formatNumberToParts(amount, {
|
||||||
|
locale,
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
currencyDisplay: 'code',
|
currencyDisplay: 'code',
|
||||||
currency,
|
currency,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue