Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/any2any.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,11 @@ func Float64tostring(f float64) string {
if f == math.Trunc(f) {
return strconv.FormatInt(int64(f), 10)
}
return strconv.FormatFloat(f, 'f', 6, 64)
// 用 15 位精度,然后用 TrimRight 去零
s := strconv.FormatFloat(f, 'f', 15, 64)
s = strings.TrimRight(s, "0")
s = strings.TrimRight(s, ".")
return s
}

// StrToFloat64 字符串转 float 64
Expand Down
11 changes: 11 additions & 0 deletions tools/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,14 @@ func MapKeys[K comparable, V any](m map[K]V) []K {
}
return keys
}

func Pluck[T any, R any](slice []T, extractor func(T) R) []R {
if len(slice) == 0 {
return []R{} // 返回空切片而非 nil,避免 nil 检查
}
result := make([]R, len(slice))
for i, item := range slice {
result[i] = extractor(item)
}
return result
}
Loading