go-humanize icon indicating copy to clipboard operation
go-humanize copied to clipboard

Allow to skip trailing zeros in FormatFloat

Open niondir opened this issue 7 years ago • 1 comments

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?

niondir avatar Feb 12 '18 10:02 niondir

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"), ".")

phattv avatar Jul 26 '19 03:07 phattv