MCPcopy
hub / github.com/git-lfs/git-lfs / FormatBytesUnit

Function FormatBytesUnit

tools/humanize/humanize.go:119–133  ·  view source on GitHub ↗

FormatBytesUnit outputs the given number of bytes "s" as a quantity of the given units "u" to the nearest half within .01.

(s, u uint64)

Source from the content-addressed store, hash-verified

117// FormatBytesUnit outputs the given number of bytes "s" as a quantity of the
118// given units "u" to the nearest half within .01.
119func FormatBytesUnit(s, u uint64) string {
120 var rounded float64
121 if s < 10 {
122 rounded = float64(s)
123 } else {
124 rounded = math.Floor(float64(s)/float64(u)*10+.5) / 10
125 }
126
127 format := "%.0f"
128 if rounded < 10 && u > 1 {
129 format = "%.1f"
130 }
131
132 return fmt.Sprintf(format, rounded)
133}
134
135// FormatByteRate outputs the given rate of transfer "r" as the quotient of "s"
136// (the number of bytes transferred) over "d" (the duration of time that those

Callers 4

AssertMethod · 0.92
PrintMethod · 0.92
FormatBytesFunction · 0.85
FormatByteRateFunction · 0.85

Calls

no outgoing calls

Tested by 1

AssertMethod · 0.74