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 option for the curency layout #1672
Comments
@Joerg-L Thank you for creating the issue! Indeed, different currencies may have different formats and currently we use a naive approach for simplicity. I wonder if having a setting for locale like Would you find it more useful instead of manually providing a format template? I can see an extra complexity with parsing this and handling incorrect formats, but maybe I'm missing a use case here. |
@vdmgolub I'm completely fine with your approach. Related to text translation: |
Oh! That's right, I guess many teams in engineering would use English language for communication. But it seems like you would still prefer to see the costs in your local currency AND format. Very interesting! :) I'll bring this topic to the team to discuss what would work better in a long run. Thank you for bringing this up! We'll update the issue when we have more details. 👍 |
We use the go-money package and that already has a template mechanism for positioning the currency symbol. I'm guessing it wouldn't be too difficult to let users set an alternate template. |
@tim775 It's not just the symbol position, in Germany comma delimits the decimal part, and dot is a thousands separator. That is why I thought about introducing locale notion. |
@Joerg-L I've updated the description with a proposed solution. We thought the ENV var would be a good start for now. It's open for community contributions. If you feel like implementing it, please leave a comment and I'll assign it to you. :) Thanks again for creating the issue! It should be a nice enhancement for the app. :) |
@vdmgolub thanks for that update. If I would have any clue in devloping such things, I would like to contribute, to be honset, I don't have a clue. |
@Joerg-L No worries at all, was checking in case you're interested to try new things :) Oops, I need to elaborate it better in the description: the |
Hi, I am working on this, please assign it to me. |
Custom currency and formatting support is now live in the v0.10.12 release. Thanks @fatihtokus for your contribution. |
When setting
INFRACOST_CURRENCY=EUR
the format of the currency values is not correct.Current Format
Expected format
To make it as flexible as possible, it would be helpfull do define an addition environment variable to define the logic like
USD can be the default.
Proposed solution
To provide flexibility in displaying costs in local currency we can introduce a new ENV var
INFRACOST_CURRENCY_FORMAT
that accepts a template string in format$123,456.7890
similar to Go's date format. Examples:$123,456.78
123.456,78$
123,456.789 $
CLI uses go-money package where
Currency
struct hasDecimal
,Thousand
,Fraction
andTemplate
attributes.It would parse the ENV var and extract related parts to override these attributes for selected currency. If ENV var is not set - don't do anything and use default
go-money
's behavior. Rules:Thousand
character will be located between123
and456
Decimal
- between456
and7*
(or$
or space if fraction is 0)Fraction
-7
for 1,78
- 2,789
- 3,7890
- 4Template
- replacing123,456.7890
with1
would result with1 $
,go-money
package will replace$
with the proper currency character.Note for community
Please 👍 if you'd like to upvote this or receive updates.
The text was updated successfully, but these errors were encountered: