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

Function CalculatePercentage

internal/ui/utils/formatting.go:151–157  ·  view source on GitHub ↗

CalculatePercentage safely calculates percentage from used and total values Returns 0.0 if total is 0 to avoid division by zero.

(used, total float64)

Source from the content-addressed store, hash-verified

149// CalculatePercentage safely calculates percentage from used and total values
150// Returns 0.0 if total is 0 to avoid division by zero.
151func CalculatePercentage(used, total float64) float64 {
152 if total <= 0 {
153 return 0.0
154 }
155
156 return (used / total) * 100
157}
158
159// CalculatePercentageInt safely calculates percentage from used and total int64 values
160// Returns 0.0 if total is 0 to avoid division by zero.

Callers 2

UpdateMethod · 0.92
UpdateMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected