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

Lost zeros using SIWithDigits with 0 decimals 200.0 becomes "2" #106

Closed
phfix opened this issue Dec 13, 2022 · 5 comments
Closed

Lost zeros using SIWithDigits with 0 decimals 200.0 becomes "2" #106

phfix opened this issue Dec 13, 2022 · 5 comments

Comments

@phfix
Copy link

phfix commented Dec 13, 2022

Hi,
I have noticed that the function humanize.SIWithDigits doesn't handle when the value to be rounded doesn't have any decimals.

Example:
fmt.Printf("20 -> %s\n", humanize.SIWithDigits(20.0, 0, "Unit"))
fmt.Printf("200 -> %s\n", humanize.SIWithDigits(200.0, 0, "Unit"))

Output:
20 -> 2 Unit
200 -> 2 Unit

I think the function stripTrailingZeros needs to check if "." is in the string at all

Workaround for now it to not use 0 decimals

@dustin
Copy link
Owner

dustin commented Jan 10, 2023

Thanks for reporting this. Was kind of egregious.

@dustin dustin closed this as completed in 9ec74ab Jan 10, 2023
@williambrode
Copy link

Thanks for fixing - I just debugged our issue down to this bug too.

@williambrode
Copy link

@dustin Don't you need to add a new tag for us to get this fix? I see there is only v1.0.0 from 2018.

@dustin
Copy link
Owner

dustin commented Jan 13, 2023

I just pushed a new tag v1.0.1. Let me know if that works for you.

@williambrode
Copy link

Yes, that did the trick go get github.com/dustin/go-humanize now pulls down v1.0.1

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

3 participants