Skip to content

Add support for decimal places in currency filter #2676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2016
Merged

Add support for decimal places in currency filter #2676

merged 1 commit into from
Apr 18, 2016

Conversation

phanan
Copy link
Member

@phanan phanan commented Apr 15, 2016

I know @yyx990803 has little intention to extend these core functionality, but IMHO you either support something fully or you don't at all. So…

Currently the "currency" filter only accepts one argument: the currency symbol. The number of decimal places is fixed as 2. This can cause troubles with several currencies out there whose number of decimal places can be 0 (e.g. Japanese Yen or Vietnamese Dong) or 3 (e.g. Jordanian Dinar).

This commit modifies the filter to accept an extra optional argument: decimal places, which defaults to 2. With this, one can write {{ 1234 | currency '¥' 0 }} to properly display a Yen value. Backward compatibility is maintained.

(Just realized there's a StackOverflow question about this very issue, where the OP was recommended to create a new filter, which is anti-DRY IMO).

Currently the "currency" filter only accepts one argument: the currency
symbol. The number of decimal places is fixed as 2. This can cause
troubles with several currencies out there whose number of decimal places
can be 0 (e.g. Japanese Yen or Vietnamese Dong) or 3 (e.g. Jordanian
Dinar).
This commit modifies the filter to accept an extra optional argument:
decimal places, which defaults to 2. With this, one can write `{{ 1234 |
currency '¥' 0 }}` to properly display a Yen value. Backward
compatibility is maintained.
@blake-newman
Copy link
Member

blake-newman commented Apr 15, 2016

I still think this should be a separate filter, called precision. It has way more use cases, and can be chained with this.

@phanan
Copy link
Member Author

phanan commented Apr 15, 2016

I personally don't think precision needs to be a filter – it's a mere toFixed() call after all – or if the users want to, they can create it easily. This commit on the other hand extends what Vue currently has.

@phanan
Copy link
Member Author

phanan commented Apr 15, 2016

Also, decimal places is certainly a currency property and should be implemented as such.

@blake-newman
Copy link
Member

I agree to some extent with your argument, I suppose this is down to how @yyx990803 sees it best implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants