diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/dustin/go-humanize/commaf.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/dustin/go-humanize/commaf.go')
-rw-r--r-- | vendor/github.com/dustin/go-humanize/commaf.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/dustin/go-humanize/commaf.go b/vendor/github.com/dustin/go-humanize/commaf.go new file mode 100644 index 0000000..2bc83a0 --- /dev/null +++ b/vendor/github.com/dustin/go-humanize/commaf.go | |||
@@ -0,0 +1,41 @@ | |||
1 | //go:build go1.6 | ||
2 | // +build go1.6 | ||
3 | |||
4 | package humanize | ||
5 | |||
6 | import ( | ||
7 | "bytes" | ||
8 | "math/big" | ||
9 | "strings" | ||
10 | ) | ||
11 | |||
12 | // BigCommaf produces a string form of the given big.Float in base 10 | ||
13 | // with commas after every three orders of magnitude. | ||
14 | func BigCommaf(v *big.Float) string { | ||
15 | buf := &bytes.Buffer{} | ||
16 | if v.Sign() < 0 { | ||
17 | buf.Write([]byte{'-'}) | ||
18 | v.Abs(v) | ||
19 | } | ||
20 | |||
21 | comma := []byte{','} | ||
22 | |||
23 | parts := strings.Split(v.Text('f', -1), ".") | ||
24 | pos := 0 | ||
25 | if len(parts[0])%3 != 0 { | ||
26 | pos += len(parts[0]) % 3 | ||
27 | buf.WriteString(parts[0][:pos]) | ||
28 | buf.Write(comma) | ||
29 | } | ||
30 | for ; pos < len(parts[0]); pos += 3 { | ||
31 | buf.WriteString(parts[0][pos : pos+3]) | ||
32 | buf.Write(comma) | ||
33 | } | ||
34 | buf.Truncate(buf.Len() - 1) | ||
35 | |||
36 | if len(parts) > 1 { | ||
37 | buf.Write([]byte{'.'}) | ||
38 | buf.WriteString(parts[1]) | ||
39 | } | ||
40 | return buf.String() | ||
41 | } | ||