mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-13 01:14:59 +03:00
c321933a54
Co-authored-by: Javier Guerrero <javier.guerrero@github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
17 lines
421 B
Go
17 lines
421 B
Go
package common
|
|
|
|
import "strconv"
|
|
|
|
// FormatTraffic formats traffic bytes into human-readable units (B, KB, MB, GB, TB, PB).
|
|
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 strconv.FormatFloat(size, 'f', 2, 64) + units[unitIndex]
|
|
}
|