mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-04 02:13:33 +00:00
🔨 Round off durations before printing
This commit is contained in:
21
utils/int.go
Normal file
21
utils/int.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
type Number interface {
|
||||
int | int8 | int16 | int32 | int64
|
||||
}
|
||||
|
||||
func NumLen[T Number](n T) T {
|
||||
if n < 0 {
|
||||
n = -n
|
||||
}
|
||||
if n == 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
var count T = 0
|
||||
for n > 0 {
|
||||
n /= 10
|
||||
count++
|
||||
}
|
||||
return count
|
||||
}
|
Reference in New Issue
Block a user