Skip to content

Allow locale number formatting to be applied without grouping #51619

@adam-marshall

Description

@adam-marshall

Which @angular/* package(s) are relevant/related to the feature request?

@angular/common

Description

formatNumber allows locale formatting which also will group digits with a group separator character, according to the locale.

e.g. 1234 becomes 1,234

However in some circumstances locale formatting may be desirable, to use the correct currency symbol or to use the correct decimal point character - without also grouping the digits.

e.g. calling

import { formatNumber  } from '@angular/common';
...

const value = 1234.5;
const formattedValue = formatNumber(value, 'de-DE', '1.2');

console.log(formattedValue); // this will be 1.234,50 but there is no way to make it 1234,50

Proposed solution

Intl.NumberFormat exposes a useGrouping option, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping.

This could use a similar solution, e.g. expose a flag higher up as an argument to formatNumber to allow grouping to be optionally applied.

Alternatives considered

Several users have written, or have been advised to write, their own custom logic to strip out the commas afterwards. This seems counter productive and possibly bad advice:

https://itecnote.com/tecnote/angular-removing-comma-from-number-pipe-in-angular2/
https://stackoverflow.com/questions/47992859/removing-comma-from-number-pipe-in-angular2
https://stackoverflow.com/questions/56544851/can-angulars-decimal-pipe-display-4-integer-digits-without-a-comma
https://stackoverflow.com/questions/64132585/how-to-remove-1000-factor-commas-from-currency-pipe-in-angular

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common package

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions