MCPcopy
hub / github.com/prometheus/prometheus / FormatOpenMetricsFloat

Function FormatOpenMetricsFloat

model/labels/float.go:35–60  ·  view source on GitHub ↗

FormatOpenMetricsFloat works like the usual Go string formatting of a float but appends ".0" if the resulting number would otherwise contain neither a "." nor an "e".

(f float64)

Source from the content-addressed store, hash-verified

33// but appends ".0" if the resulting number would otherwise contain neither a
34// "." nor an "e".
35func FormatOpenMetricsFloat(f float64) string {
36 // A few common cases hardcoded.
37 switch {
38 case f == 1:
39 return "1.0"
40 case f == 0:
41 return "0.0"
42 case f == -1:
43 return "-1.0"
44 case math.IsNaN(f):
45 return "NaN"
46 case math.IsInf(f, +1):
47 return "+Inf"
48 case math.IsInf(f, -1):
49 return "-Inf"
50 }
51 bp := floatFormatBufPool.Get().(*[]byte)
52 defer floatFormatBufPool.Put(bp)
53
54 *bp = strconv.AppendFloat((*bp)[:0], f, 'g', -1, 64)
55 if bytes.ContainsAny(*bp, "e.") {
56 return string(*bp)
57 }
58 *bp = append(*bp, '.', '0')
59 return string(*bp)
60}

Callers 4

getMagicLabelMethod · 0.92
ConvertNHCBToClassicFunction · 0.92
funcHistogramQuantilesFunction · 0.92

Calls 2

GetMethod · 0.65
PutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…