Skip to content

Commit

Permalink
format bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Nov 17, 2023
1 parent f91bb2f commit 9f04e5a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions format/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ const (
KiloByte = Byte * 1000
MegaByte = KiloByte * 1000
GigaByte = MegaByte * 1000
TeraByte = GigaByte * 1000
)

func HumanBytes(b int64) string {
switch {
case b > TeraByte:
return fmt.Sprintf("%.1f TB", float64(b)/TeraByte)
case b > GigaByte:
return fmt.Sprintf("%.1f GB", float64(b)/GigaByte)
case b > MegaByte:
Expand Down

0 comments on commit 9f04e5a

Please sign in to comment.