-
Notifications
You must be signed in to change notification settings - Fork 63
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
trim trailing 0s #151
Comments
Maybe you could copy some code from my formatter: https://github.com/bojanz/currency/blob/master/formatter.go |
I'm afraid I don't understand it. What I'm trying to say:
|
Apologies, I read your issue in a hurry and thought you were looking for a better formatting helper. |
Just for string formatting? You can use the width verbs. Quantize does what you want too, but modifies the receiver. |
ah, this is for the second use case - and works sometimes, but not always func TestAsPercentageWithPrecision(t *testing.T) {
assert.Equal(t, "100.00", withPrecision("99.999999", 2)) //fails because it's "100.0"
}
func withPrecision(s string, precision uint) string {
f := parse(s)
return fmt.Sprintf("%s", f.Quantize(int(precision)))
}
func parse(s string) *decimal.Big {
p, _ := new(decimal.Big).SetString(s)
return p
} |
@zeitlinger Call Looking at the date of this issue... Is this library still supported, or "kind of archived"? |
@lotodore I just haven't had a lot of time to work on it lately. But I will always make time to review and accept PRs. |
Is there a way to trim trailing 0s like the following?
Is there a way to format a number with a given number of digits after the "." - something easier than this
The text was updated successfully, but these errors were encountered: