summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dustin/go-humanize
diff options
context:
space:
mode:
authorMartin Kraft <martinkraft@gmail.com>2018-05-22 12:54:00 -0400
committerMartin Kraft <martinkraft@gmail.com>2018-05-22 12:54:00 -0400
commit4c683aff7627040ff811f065848a820b2cb19d59 (patch)
tree668061e8acfd8827fd02bab18a998b7986944296 /vendor/github.com/dustin/go-humanize
parenteb78d273f39202046fa71555a5a19b0ec8a95cb3 (diff)
parent1af1bce6199597bb2d41ddcdc00ef0f28a73c83e (diff)
downloadchat-4c683aff7627040ff811f065848a820b2cb19d59.tar.gz
chat-4c683aff7627040ff811f065848a820b2cb19d59.tar.bz2
chat-4c683aff7627040ff811f065848a820b2cb19d59.zip
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'vendor/github.com/dustin/go-humanize')
-rw-r--r--vendor/github.com/dustin/go-humanize/comma.go8
-rw-r--r--vendor/github.com/dustin/go-humanize/ftoa.go25
-rw-r--r--vendor/github.com/dustin/go-humanize/si.go10
3 files changed, 42 insertions, 1 deletions
diff --git a/vendor/github.com/dustin/go-humanize/comma.go b/vendor/github.com/dustin/go-humanize/comma.go
index 13611aaab..520ae3e57 100644
--- a/vendor/github.com/dustin/go-humanize/comma.go
+++ b/vendor/github.com/dustin/go-humanize/comma.go
@@ -76,6 +76,14 @@ func Commaf(v float64) string {
return buf.String()
}
+// CommafWithDigits works like the Commaf but limits the resulting
+// string to the given number of decimal places.
+//
+// e.g. CommafWithDigits(834142.32, 1) -> 834,142.3
+func CommafWithDigits(f float64, decimals int) string {
+ return stripTrailingDigits(Commaf(f), decimals)
+}
+
// BigComma produces a string form of the given big.Int in base 10
// with commas after every three orders of magnitude.
func BigComma(b *big.Int) string {
diff --git a/vendor/github.com/dustin/go-humanize/ftoa.go b/vendor/github.com/dustin/go-humanize/ftoa.go
index c76190b10..1c62b640d 100644
--- a/vendor/github.com/dustin/go-humanize/ftoa.go
+++ b/vendor/github.com/dustin/go-humanize/ftoa.go
@@ -1,6 +1,9 @@
package humanize
-import "strconv"
+import (
+ "strconv"
+ "strings"
+)
func stripTrailingZeros(s string) string {
offset := len(s) - 1
@@ -17,7 +20,27 @@ func stripTrailingZeros(s string) string {
return s[:offset+1]
}
+func stripTrailingDigits(s string, digits int) string {
+ if i := strings.Index(s, "."); i >= 0 {
+ if digits <= 0 {
+ return s[:i]
+ }
+ i++
+ if i+digits >= len(s) {
+ return s
+ }
+ return s[:i+digits]
+ }
+ return s
+}
+
// Ftoa converts a float to a string with no trailing zeros.
func Ftoa(num float64) string {
return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64))
}
+
+// FtoaWithDigits converts a float to a string but limits the resulting string
+// to the given number of decimal places, and no trailing zeros.
+func FtoaWithDigits(num float64, digits int) string {
+ return stripTrailingZeros(stripTrailingDigits(strconv.FormatFloat(num, 'f', 6, 64), digits))
+}
diff --git a/vendor/github.com/dustin/go-humanize/si.go b/vendor/github.com/dustin/go-humanize/si.go
index b24e48169..ae659e0e4 100644
--- a/vendor/github.com/dustin/go-humanize/si.go
+++ b/vendor/github.com/dustin/go-humanize/si.go
@@ -93,6 +93,16 @@ func SI(input float64, unit string) string {
return Ftoa(value) + " " + prefix + unit
}
+// SIWithDigits works like SI but limits the resulting string to the
+// given number of decimal places.
+//
+// e.g. SIWithDigits(1000000, 0, "B") -> 1 MB
+// e.g. SIWithDigits(2.2345e-12, 2, "F") -> 2.23 pF
+func SIWithDigits(input float64, decimals int, unit string) string {
+ value, prefix := ComputeSI(input)
+ return FtoaWithDigits(value, decimals) + " " + prefix + unit
+}
+
var errInvalid = errors.New("invalid input")
// ParseSI parses an SI string back into the number and unit.