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

Add precision and round functions #76

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Tonyfilla
Copy link

Hi, Dustin.
I like your lib go-humanize. And I want to suggest some improvements.
This changes will allow me to use this library to manage size disk correctly. When we work with bytes to manage size disk we face to some problems with rounding values. For example, if you want to create a disk partition you have to see how much free space disk have. So, if we ask to create 1GB partition however we have 999.99 MB we got an error.
For these cases, I offer to add precision and different rounding functions.
These changes don’t affect for main library functional and maintain compatibility with previous version your lib.
Please, review this code.
With hope to your approvement, Tony.

Comment on lines +78 to +79
f := fmt.Sprintf("%%.%df", precision)
res := fmt.Sprintf(f, val)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI:
you can simplify these two lines to:

res := fmt.Sprintf("%.*f",precision,val)

play

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

Successfully merging this pull request may close these issues.

2 participants