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

Proper way to do string formatting #427

Open
rdbo opened this issue Mar 9, 2024 · 1 comment
Open

Proper way to do string formatting #427

rdbo opened this issue Mar 9, 2024 · 1 comment

Comments

@rdbo
Copy link
Contributor

rdbo commented Mar 9, 2024

I tried the following ways to format a float to have 2 decimal place precision, but neither worked:

{{ "%.2f" % price }}

Result: invalid operation: tried to use % operator on unsupported types string and number

{{ "%.2f"|format(price) }}

Result: unknown filter: filter format is unknown

Is it possible to format strings like this without creating a custom filter? If so, what is the proper way to do it?

@mitsuhiko
Copy link
Owner

Today a custom filter is the only thing you can do. I would love to have a formatting filter in minijinja-contrib but it's quite a bit of effort to create and I did not have the time yet. Happy to accept contributions.

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