MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / FormatBytes

Function FormatBytes

internal/ui/utils/formatting.go:41–61  ·  view source on GitHub ↗

FormatBytes formats a byte count to a human-readable format with dynamic units Always shows 2 decimal places and chooses the most appropriate unit (GB, TB, PB).

(bytes int64)

Source from the content-addressed store, hash-verified

39// FormatBytes formats a byte count to a human-readable format with dynamic units
40// Always shows 2 decimal places and chooses the most appropriate unit (GB, TB, PB).
41func FormatBytes(bytes int64) string {
42 const (
43 GB = 1024 * 1024 * 1024
44 TB = 1024 * GB
45 PB = 1024 * TB
46 )
47
48 bytesFloat := float64(bytes)
49
50 switch {
51 case bytes >= PB:
52 return fmt.Sprintf("%.2f PB", bytesFloat/PB)
53 case bytes >= TB:
54 return fmt.Sprintf("%.2f TB", bytesFloat/TB)
55 case bytes >= GB:
56 return fmt.Sprintf("%.2f GB", bytesFloat/GB)
57 default:
58 // For values less than 1GB, still show in GB with decimals
59 return fmt.Sprintf("%.2f GB", bytesFloat/GB)
60 }
61}
62
63// FormatBytesFloat converts float64 GB values to human-readable format
64// Input is assumed to be in GB, converts to appropriate units with 2 decimal places.

Callers 9

UpdateMethod · 0.92
DisplayBackupsMethod · 0.92
UpdateMethod · 0.92
UpdateMethod · 0.92
showStorageSummaryMethod · 0.92
showStorageContentMethod · 0.92
updateStatsMethod · 0.92
formatMemoryCellFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected