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

Commaf which rounds to X decimal places #18

Closed
bramp opened this issue Apr 4, 2015 · 3 comments
Closed

Commaf which rounds to X decimal places #18

bramp opened this issue Apr 4, 2015 · 3 comments

Comments

@bramp
Copy link
Contributor

bramp commented Apr 4, 2015

humanize.Commaf(10772.08207) // Returns "10,772.082074"

Could I have a

humanize.Commaf(10772.08207, 2) // Returns "10,772.08"

?

Or do you suggest an alternative way to round the number, before humanize'ng? Thanks.

@ghost
Copy link

ghost commented Jul 19, 2015

I'd like to second this. Right now I am doing:

  fl := 123456.789  // this works as expected and gives "123,456.79"
  fl := 123456.0  // this gives "123,456"....notice it truncates the decimals if they are .00000000
  sss := fmt.Sprintf("%.2f", fl)
  if ffl, err := strconv.ParseFloat(sss, 64); err == nil {  // convert it back to a float...very clunky!
    log.Println(sss, humanize.Commaf(ffl))
  } else {
    log.Println(err)
  }

However, as you can see, the decimals get truncated if they are zero....this also seems very clunky.

@dmitshur
Copy link
Collaborator

Was this issue resolved by PR #60 (which has been recently merged), or is there more to do here? /cc @bramp

@bramp
Copy link
Contributor Author

bramp commented Apr 21, 2018

Yup #60 fixes this issue

@bramp bramp closed this as completed Apr 21, 2018
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