[Feature Request] Currency Pipe: improved digit info options

This issue has been created since 2022-09-19.

Which @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.

angular-robot[bot] wrote this answer on 2022-09-21

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

FonecaBot2 wrote this answer on 2022-09-21

I can start working on this c:

kbrilla wrote this answer on 2022-09-27

I think one soultion would be to create new Pipes based on Intl API

const format = new Intl.NumberFormat("en-US", {style: 'currency', minimumFractionDigits: 2, trailingZeroDisplay: 'stripIfInteger', currency: 'USD'}); 

format.format(3)    
//  $3
format.format(3.1)
//  $3.10

If not maybe reusing the term trailingZeroDisplay option would be good for the current API
with two values as in Intl API - NumberFormat
NumberFormat

trailingZeroDisplay Experimental
A string expressing the strategy for displaying trailing zeros on whole numbers. The default is "auto".

"auto": keep trailing zeros according to minimumFractionDigits and minimumSignificantDigits.
"stripIfInteger": remove the fraction digits if they are all zero. This is the same as auto if any of the fraction digits is non-zero.

as for Intl API there are already polyfills for it here polyfill

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-09-30
Star Count 84080
Watcher Count 3064
Fork Count 22235
Issue Count 1197

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Invoke some functions of @cornerstonejs/core cache will cause page crash 2 2022-08-30 2022-09-27
no way to remove a provider from user 1 2022-07-21 2022-09-18
Bump OpenXR to crates.io version 0 2021-09-24 2022-04-07
Add simple debug interface 2 2021-10-08 2022-04-07
Invert control of app 0 2021-09-28 2022-04-07
Add features to debugger 0 2021-11-18 2022-07-16
LocalStorage capacity exceeded in debugger 0 2021-12-08 2022-09-25
Simulator does not work on MacBook running Windows 0 2021-09-24 2022-08-17
KubevirtCluster not "ready" and cluster stuck in provisioning for a long time 5 2022-08-10 2022-09-17
Add project description to PyPi Page 0 2021-01-30 2022-08-02
[Feature request]: Dark mode GUI 7 2022-06-22 2022-09-02
[Feature request]: per game input settings 0 2022-06-22 2022-09-02
geonetwork - master - groups synced are named with their short name rather than full name 0 2022-02-07 2022-08-07
Request to get Community solution for Exercise 'ex_4' in '1-Introduction' 0 2022-01-22 2022-09-13
Request to get Community solution for Exercise 'ex_1' in '11-Planning-And-Acting-In-The-Real-World' 0 2021-12-21 2022-09-13
[debug] 尝试使用公网ip时出错 3 2020-06-13 2022-01-23
ModuleNotFoundError: 'pyorbital' is not a package 3 2021-04-30 2022-09-16
Colour inversion for terminal cursor 5 2021-12-04 2022-07-07
Configurable shell timeouts 6 2021-10-06 2022-08-02
passport implmentation - profile.id or accessToken for 'value' property in claims? 1 2018-09-01 2022-09-29
DateTime + nil behavior is incorrect 0 2022-08-17 2022-09-16
All episodes in Inbox have inbox icon 1 2022-09-04 2022-09-19
[Feature Request]: Simple Update 4 2022-01-28 2022-09-22
Prysm validator (post-merge) support for multiple override fee recipient addresses based on multiple validators 12 2021-10-08 2022-07-27
Refactor settings: improve signature preference 1 2021-11-16 2022-09-27
SQL query response looks different in Taos CLI vs. Grafana 0 2021-12-22 2021-12-26
主机名修改后taos数据库无法启动 0 2021-12-23 2021-12-17
TAOS Data Storytelling Fest — My Journey with TDengine 0 2021-12-23 2022-09-25
Disclosure page has multiple identical page fragment id's 0 2022-01-15 2022-08-21
Nuclei-AWS API gateway integration 0 2022-09-23 2022-09-17
How to remove Masking on Form Submit 1 2022-05-17 2022-09-02
OLM package installation page should show the "default" channel by default 6 2022-03-15 2022-09-12
Can't seem to get mongo_tail to work 0 2021-04-01 2022-09-11
Asset catalogs in sub assemblies replace main assembly cataglos 4 2022-08-30 2022-09-21
distro request: Q4OS 2 2021-11-25 2022-09-27
AttributeError: module 'numpy' has no attribute 'float64' 3 2021-07-06 2022-09-25
BLE failed to get charactreristic value after reconnection (IDFGH-7970) 12 2022-08-02 2022-08-22
[Question] Visual Studio 2022 solution gRPC projects regeneration on each compilation without changes 2 2022-04-08 2022-09-25
[FEA] Hash map design that supports reduce by key 2 2020-10-20 2022-08-18
Open ended date_from 0 2021-12-17 2022-09-03
Slot Request for LeewayHertz 1 2022-08-19 2022-09-17
Issues with iAqualink Integration 4 2022-07-17 2022-09-20
parse json to Dictionary and nested Dictionaries 2 2019-04-26 2022-02-08
trace.aggregate record size 216167 exceeds max message size of 65536 bytes 0 2022-08-18 2022-08-20
More flexible `mz_transform::attribute` API 0 2022-08-23 2022-09-27
Map download menu, Açores (Azores) not under proper sub menu 3 2022-02-27 2022-08-05
Trace with points > 100 editable only with high high zoom 5 2022-02-24 2022-08-30
CloudEvents output data format support 2 2021-11-24 2022-09-14
[Security Solution] Adding notes to a Timeline template (where notes are not applicable) prevents the template from being saved 2 2022-01-20 2022-07-20
error I am unable to resolve 2 2022-02-22 2022-09-29