This commit is contained in:
xing 2022-11-17 14:08:26 +08:00
parent 1a72552b41
commit 1a2c50c7dd
2 changed files with 33 additions and 0 deletions

View File

@ -330,3 +330,7 @@ func SliceChunk[T any](arr []T, size int) [][]T {
} }
return r return r
} }
func NumberToString[T IntNumber | ~float64 | ~float32](n T) string {
return fmt.Sprintf("%v", n)
}

View File

@ -768,3 +768,32 @@ func TestSum(t *testing.T) {
}) })
} }
} }
func TestNumberToString(t *testing.T) {
type args struct {
n float64
}
tests := []struct {
name string
args args
want string
}{
{
name: "t1",
args: args{n: 111},
want: "111",
},
{
name: "t2",
args: args{n: 111.222222},
want: "111.222222",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NumberToString(tt.args.n); got != tt.want {
t.Errorf("NumberToString() = %v, want %v", got, tt.want)
}
})
}
}