With the latest updates few days ago, my solution to round the values doesn’t work anymore, and I can’t understand why I’m seeing a value with tons of decimals, for example this alert returns me the correct value in Grafana ed everywhere, but when the alert is triggered, Grafana do it with a tons of decimals, here the screenshots to explain:
If your data displays an unnecessarily large number of digits to the right of the decimal (such as 2.355555555555 shown above), and you want your Grafana alerts to be more legible (for example, 2.36), try using {{ printf "%.2f" $v }}
In annotation AlertValues, we could write the following:
{{ with $values }} {{ range $k, $v := . }} CPU: {{ printf "%.2f" $v }} %
{{ end }} {{ end }}
Hi! In this example $v is a structure (it contains Labels and a Value). When we attempt to print this structure in a template with $v it calls the String method on this structure, which returns the floating point value as a string without rounding to some number of decimal places.
{{ with $values }}{{ range $k, $v := . }}CPU: {{ printf "%.2f" $v }}%
{{ end }} {{ end }}
To use the raw floating point value just change the argument to printf from $v to $v.Value:
{{ with $values }}{{ range $k, $v := . }}CPU: {{ printf "%.2f" $v.Value }}%
{{ end }} {{ end }}