more work on the transfer kitten

This commit is contained in:
Kovid Goyal
2023-06-04 22:20:11 +05:30
parent d6df77c83d
commit 5d361757a2
2 changed files with 35 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ package humanize
import (
"fmt"
"math"
"strconv"
"strings"
"golang.org/x/exp/constraints"
)
@@ -91,3 +93,12 @@ func Size[T constraints.Integer | constraints.Float](s T, opts ...SizeOptions) s
}
return prefix + humanize_bytes(uint64(s), float64(o.Base), sizes, o.Separator)
}
func FormatNumber[T constraints.Float](n T, max_num_of_decimals ...int) string {
prec := 2
if len(max_num_of_decimals) > 0 {
prec = max_num_of_decimals[0]
}
ans := strconv.FormatFloat(float64(n), 'f', prec, 64)
return strings.TrimRight(strings.TrimRight(ans, "0"), ".")
}