diff --git a/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts b/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts index 50be87adf69..9dd503cea6b 100644 --- a/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts +++ b/superset-frontend/packages/superset-ui-core/src/currency-format/CurrencyFormatter.ts @@ -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)}`; } } diff --git a/superset-frontend/packages/superset-ui-core/test/currency-format/CurrencyFormatter.test.ts b/superset-frontend/packages/superset-ui-core/test/currency-format/CurrencyFormatter.test.ts index b731b1ba498..8f158865769 100644 --- a/superset-frontend/packages/superset-ui-core/test/currency-format/CurrencyFormatter.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/currency-format/CurrencyFormatter.test.ts @@ -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' },