fix(table): keep d3-format semantics when applying currency formatting (#37039)

This commit is contained in:
Jonathan Alberth Quispe Fuentes
2026-01-13 06:59:31 -05:00
committed by GitHub
parent 5f58241795
commit ad3812edd7
2 changed files with 11 additions and 6 deletions

View File

@@ -60,7 +60,11 @@ class CurrencyFormatter extends ExtensibleFunction {
}
getNormalizedD3Format() {
return this.d3Format.replace(/\$|%/g, '');
return this.d3Format.replace(/\$/g, '');
}
normalizeForCurrency(value: string) {
return value.replace(/%/g, '');
}
format(value: number) {
@@ -71,10 +75,11 @@ class CurrencyFormatter extends ExtensibleFunction {
return formattedValue as string;
}
const normalizedValue = this.normalizeForCurrency(formattedValue);
if (this.currency.symbolPosition === 'prefix') {
return `${getCurrencySymbol(this.currency)} ${formattedValue}`;
return `${getCurrencySymbol(this.currency)} ${normalizedValue}`;
}
return `${formattedValue} ${getCurrencySymbol(this.currency)}`;
return `${normalizedValue} ${getCurrencySymbol(this.currency)}`;
}
}

View File

@@ -109,7 +109,7 @@ test('CurrencyFormatter:getNormalizedD3Format', () => {
currency: { symbol: 'USD', symbolPosition: 'prefix' },
d3Format: ',.1%',
});
expect(currencyFormatter4.getNormalizedD3Format()).toEqual(',.1');
expect(currencyFormatter4.getNormalizedD3Format()).toEqual(',.1%');
});
test('CurrencyFormatter:format', () => {
@@ -146,9 +146,9 @@ test('CurrencyFormatter:format', () => {
const currencyFormatterWithPercentD3 = new CurrencyFormatter({
currency: { symbol: 'USD', symbolPosition: 'prefix' },
d3Format: ',.1f%',
d3Format: ',.1%',
});
expect(currencyFormatterWithPercentD3(VALUE)).toEqual('$ 56,100,057.0');
expect(currencyFormatterWithPercentD3(VALUE)).toEqual('$ 5,610,005,700.0');
const currencyFormatterWithCurrencyD3 = new CurrencyFormatter({
currency: { symbol: 'PLN', symbolPosition: 'suffix' },