MCPcopy
hub / github.com/dgraph-io/dgraph / niceFloat

Function niceFloat

dgraph/cmd/bulk/progress.go:136–154  ·  view source on GitHub ↗
(f float64)

Source from the content-addressed store, hash-verified

134var suffixes = [...]string{"", "k", "M", "G", "T"}
135
136func niceFloat(f float64) string {
137 idx := 0
138 for f >= 1000 {
139 f /= 1000
140 idx++
141 }
142 if idx >= len(suffixes) {
143 return fmt.Sprintf("%f", f)
144 }
145 suf := suffixes[idx]
146 switch {
147 case f >= 100:
148 return fmt.Sprintf("%.1f%s", f, suf)
149 case f >= 10:
150 return fmt.Sprintf("%.2f%s", f, suf)
151 default:
152 return fmt.Sprintf("%.3f%s", f, suf)
153 }
154}

Callers 1

reportOnceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected