mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
18 lines
321 B
Go
18 lines
321 B
Go
![]() |
package common
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func FormatTraffic(trafficBytes int64) string {
|
||
|
units := []string{"B", "KB", "MB", "GB", "TB", "PB"}
|
||
|
unitIndex := 0
|
||
|
size := float64(trafficBytes)
|
||
|
|
||
|
for size >= 1024 && unitIndex < len(units)-1 {
|
||
|
size /= 1024
|
||
|
unitIndex++
|
||
|
}
|
||
|
return fmt.Sprintf("%.2f%s", size, units[unitIndex])
|
||
|
}
|