Skip to content
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

Format filter should support zero-padding before&after decimal place #45

Open
AaronOpfer opened this issue Apr 16, 2012 · 0 comments
Open

Comments

@AaronOpfer
Copy link

Say you wanted to format a dollar amount with tempo.js. You'd do something like this:

{{cost | format | prepend $ }}

However, if you have cents in your dollar amount, it will not be formatted in the traditional way. To be specific: if cost=float(12.10), then the above template would yield "$12.1". This does not match the desired output of "$12.10".

I propose that the format filter's syntax be extended to take up to two optional arguments. The first argument would be the number of digits that must be shown on the left of the decimal point, and the second argument would be the number of digits that must be shown on the right of the decimal point.

Some examples with cost=12.1:

{{ cost | format }} : 12.1
{{ cost | format 4 }}: 0012.1
{{ cost | format 0,2}}: 12.10
{{ cost | format 4,2}}: 0012.10

A complete template for formatting dollar amounts if this feature is implemented would be:

{{ cost | format 0,2 | prepend $ }}

@ghost ghost assigned mrolafsson Jan 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants