mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 06:54:58 +02:00
more work on the transfer kitten
This commit is contained in:
@@ -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"), ".")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user