diff --git a/helper/func.go b/helper/func.go index 1eba333..a15dfaa 100644 --- a/helper/func.go +++ b/helper/func.go @@ -330,3 +330,7 @@ func SliceChunk[T any](arr []T, size int) [][]T { } return r } + +func NumberToString[T IntNumber | ~float64 | ~float32](n T) string { + return fmt.Sprintf("%v", n) +} diff --git a/helper/func_test.go b/helper/func_test.go index 8b102ba..64a0ea1 100644 --- a/helper/func_test.go +++ b/helper/func_test.go @@ -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) + } + }) + } +}