[Feature Request] Currency Pipe: improved digit info options
See original GitHub issueWhich @angular/* package(s) are relevant/related to the feature request?
common
Description
A common way to display currencies (at least in US) is to omit the cents if the price is a round number, or to show two digits if the price is not a round number.
For example, for 3
dollars, $3
, and for 3.1
dollar, $3.10
.
There is no way to accomplish this with the current currency pipe, which only takes a range for the number of digits after the decimal. The only options either make the first price $3.00
and the second $3.10
, or the first price $3
and the second $3.1
.
Proposed solution
Extend the digitsInfo
format. Currently, the format is {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
.
As an alternative, we could offer {minIntegerDigits}.{allowedFractionDigits1},{allowedFractionDigits2}[,...]
. So the digitsInfo
for the format above would be 1.0,2
.
Alternatives considered
Alternately, one could use an *ngIf
to change out the element with the currency, and use two elements, each with a currency pipe to accomplish the above. Obviously, that is kind of messy.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:6 (4 by maintainers)
Top GitHub Comments
I think one soultion would be to create new Pipes based on Intl API
If not maybe reusing the term
trailingZeroDisplay
option would be good for the current API with two values as in Intl API - NumberFormat NumberFormatas for Intl API there are already polyfills for it here polyfill
Thank you for submitting your feature request! Looks like during the polling process it didn’t collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular’s scope, we’d encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.