diff --git a/packages/common/src/i18n/format_number.ts b/packages/common/src/i18n/format_number.ts index c78a4a7336..770b55032d 100644 --- a/packages/common/src/i18n/format_number.ts +++ b/packages/common/src/i18n/format_number.ts @@ -161,7 +161,12 @@ export function formatCurrency( return res .replace(CURRENCY_CHAR, currency) // if we have 2 time the currency character, the second one is ignored - .replace(CURRENCY_CHAR, ''); + .replace(CURRENCY_CHAR, '') + // If there is a spacing between currency character and the value and + // the currency character is supressed by passing an empty string, the + // spacing character would remain as part of the string. Then we + // should remove it. + .trim(); } /** diff --git a/packages/common/test/pipes/number_pipe_spec.ts b/packages/common/test/pipes/number_pipe_spec.ts index 8c4149fe0c..97b7970a0e 100644 --- a/packages/common/test/pipes/number_pipe_spec.ts +++ b/packages/common/test/pipes/number_pipe_spec.ts @@ -11,6 +11,7 @@ import localeEsUS from '@angular/common/locales/es-US'; import localeFr from '@angular/common/locales/fr'; import localeAr from '@angular/common/locales/ar'; import localeDeAt from '@angular/common/locales/de-AT'; +import localeDa from '@angular/common/locales/da'; import {ɵunregisterLocaleData, ɵregisterLocaleData} from '@angular/core'; import {CurrencyPipe, DecimalPipe, PercentPipe} from '@angular/common'; import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; @@ -23,6 +24,7 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin ɵregisterLocaleData(localeFr); ɵregisterLocaleData(localeAr); ɵregisterLocaleData(localeDeAt); + ɵregisterLocaleData(localeDa); }); afterAll(() => ɵunregisterLocaleData()); @@ -95,6 +97,7 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin expect(pipe.transform(12, 'EUR', 'code', '.1')).toEqual('EUR12.0'); expect(pipe.transform(5.1234, 'USD', 'code', '.0-3')).toEqual('USD5.123'); expect(pipe.transform(5.1234, 'USD', 'code')).toEqual('USD5.12'); + expect(pipe.transform(5.1234, 'USD', '')).toEqual('5.12'); expect(pipe.transform(5.1234, 'USD', 'symbol')).toEqual('$5.12'); expect(pipe.transform(5.1234, 'CAD', 'symbol')).toEqual('CA$5.12'); expect(pipe.transform(5.1234, 'CAD', 'symbol-narrow')).toEqual('$5.12'); @@ -104,6 +107,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testin expect(pipe.transform(5, 'USD', 'symbol', '', 'fr')).toEqual('5,00 $US'); expect(pipe.transform(123456789, 'EUR', 'symbol', '', 'de-at')) .toEqual('€ 123.456.789,00'); + expect(pipe.transform(5.1234, 'EUR', '', '', 'de-at')).toEqual('5,12'); + expect(pipe.transform(5.1234, 'DKK', '', '', 'da')).toEqual('5,12'); }); it('should support any currency code name', () => {