summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Conway <clconway@google.com>2018-06-22 16:30:57 -0700
committerDustin Sallings <dustin@spy.net>2018-07-12 22:29:10 -0700
commit9f541cc9db5d55bce703bd99987c9d5cb8eea45e (patch)
tree8f1940c2f0f6d672bf3e6cd97b7f937b0464bf99
parent02af3965c54e8cacf948b97fef38925c4120652c (diff)
downloadgo-humanize-9f541cc9db5d55bce703bd99987c9d5cb8eea45e.tar.xz
Adds commas to number formatting in english.Plural.v1.0.0
-rw-r--r--english/words.go4
-rw-r--r--english/words_test.go1
2 files changed, 4 insertions, 1 deletions
diff --git a/english/words.go b/english/words.go
index 26e9918..68c4948 100644
--- a/english/words.go
+++ b/english/words.go
@@ -4,6 +4,8 @@ package english
import (
"fmt"
"strings"
+
+ humanize "github.com/dustin/go-humanize"
)
// These are included because they are common technical terms.
@@ -61,7 +63,7 @@ func PluralWord(quantity int, singular, plural string) string {
// The simple English rules of regular pluralization will be used
// if the plural form is an empty string (i.e. not explicitly given).
func Plural(quantity int, singular, plural string) string {
- return fmt.Sprintf("%d %s", quantity, PluralWord(quantity, singular, plural))
+ return fmt.Sprintf("%s %s", humanize.Comma(int64(quantity)), PluralWord(quantity, singular, plural))
}
// WordSeries converts a list of words into a word series in English.
diff --git a/english/words_test.go b/english/words_test.go
index 3c1d7be..61db7b3 100644
--- a/english/words_test.go
+++ b/english/words_test.go
@@ -47,6 +47,7 @@ func TestPlural(t *testing.T) {
}{
{1, "object", "", "1 object"},
{42, "object", "", "42 objects"},
+ {1234567, "object", "", "1,234,567 objects"},
}
for _, tt := range tests {
if got := Plural(tt.n, tt.singular, tt.plural); got != tt.want {