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

Allow to skip trailing zeros in FormatFloat #68

Open
niondir opened this issue Feb 12, 2018 · 1 comment
Open

Allow to skip trailing zeros in FormatFloat #68

niondir opened this issue Feb 12, 2018 · 1 comment

Comments

@niondir
Copy link

niondir commented Feb 12, 2018

I like to format 123.123 and 123.1234 to with "up to 4" digits after the comma.
But using the format #.#### would result in 123.1230 for the first case instead of 123.123

Could we have something like #,#### = fill trailing zeros and #,**** skip trailing zeros? That would be backwards compatible. Or is there any formatting guideline that you are following?

@phattv
Copy link

phattv commented Jul 26, 2019

As far as i know there is no direct way of doing this, what you can do is
strings.TrimRight(strings.TrimRight(humanize.FormatFloat("", 123.1), "0"), ".")

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