aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dustin/go-humanize/ftoa.go
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-01-02 18:56:31 +0100
committerLibravatar Rutger Broekhoff2024-01-02 18:56:31 +0100
commit8db41da676ac8368ef7c2549d56239a5ff5eedde (patch)
tree09c427fd66de2ec1ebffc8342f5fdbb84b0701b5 /vendor/github.com/dustin/go-humanize/ftoa.go
parentd4f75fb6db22e57577867445a022227e70958931 (diff)
downloadgitolfs3-8db41da676ac8368ef7c2549d56239a5ff5eedde.tar.gz
gitolfs3-8db41da676ac8368ef7c2549d56239a5ff5eedde.zip
Delete vendor directory
Diffstat (limited to 'vendor/github.com/dustin/go-humanize/ftoa.go')
-rw-r--r--vendor/github.com/dustin/go-humanize/ftoa.go49
1 files changed, 0 insertions, 49 deletions
diff --git a/vendor/github.com/dustin/go-humanize/ftoa.go b/vendor/github.com/dustin/go-humanize/ftoa.go
deleted file mode 100644
index bce923f..0000000
--- a/vendor/github.com/dustin/go-humanize/ftoa.go
+++ /dev/null
@@ -1,49 +0,0 @@
1package humanize
2
3import (
4 "strconv"
5 "strings"
6)
7
8func stripTrailingZeros(s string) string {
9 if !strings.ContainsRune(s, '.') {
10 return s
11 }
12 offset := len(s) - 1
13 for offset > 0 {
14 if s[offset] == '.' {
15 offset--
16 break
17 }
18 if s[offset] != '0' {
19 break
20 }
21 offset--
22 }
23 return s[:offset+1]
24}
25
26func stripTrailingDigits(s string, digits int) string {
27 if i := strings.Index(s, "."); i >= 0 {
28 if digits <= 0 {
29 return s[:i]
30 }
31 i++
32 if i+digits >= len(s) {
33 return s
34 }
35 return s[:i+digits]
36 }
37 return s
38}
39
40// Ftoa converts a float to a string with no trailing zeros.
41func Ftoa(num float64) string {
42 return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64))
43}
44
45// FtoaWithDigits converts a float to a string but limits the resulting string
46// to the given number of decimal places, and no trailing zeros.
47func FtoaWithDigits(num float64, digits int) string {
48 return stripTrailingZeros(stripTrailingDigits(strconv.FormatFloat(num, 'f', 6, 64), digits))
49}