23 lines
536 B
Go
23 lines
536 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"git.milar.in/milarin/gmath"
|
||
|
)
|
||
|
|
||
|
func FormatBytes[T gmath.Integer](bytes T) string {
|
||
|
value := float64(bytes)
|
||
|
if value/1000000000000 >= 1000000000000 {
|
||
|
return fmt.Sprint("%.02fT", value/1000000000000)
|
||
|
} else if value/1000000000 >= 1000000000 {
|
||
|
return fmt.Sprint("%.02fG", value/1000000000)
|
||
|
} else if value/1000000 >= 1000000 {
|
||
|
return fmt.Sprint("%.02fM", value/1000000)
|
||
|
} else if value/1000 >= 1000 {
|
||
|
return fmt.Sprint("%.02fK", value/1000)
|
||
|
} else {
|
||
|
return fmt.Sprint("%.02fB", value)
|
||
|
}
|
||
|
}
|