grafanainfluxdbdivide

InfluxDB Influx divide value by 10 results in zero


I have a field called epv1today which holds values that I need to divide by ten. As long as the value has two digits, the following code example works. As soon as the value has one digit, all I get is a zero value.

Value 21 results in 2.1

Value 2 results in 0 but should be 0.2

Code:

from(bucket: "watt")
    |> range(start: today())
    |> filter(fn: (r) => r["_measurement"] == "<SerialNumber>")
    |> filter(fn: (r) => r["_field"] == "epv1today")
    |> map(fn: (r) => ({r with _value: r._value / 10}))
    |> last()

What am I missing?


Solution

  • The solution I was looking for is:

    from(bucket: "watt")
        |> range(start: today())
        |> filter(fn: (r) => r["_measurement"] == "<SerialNumber>")
        |> filter(fn: (r) => r["_field"] == "epv1today")
        |> toFloat()
        |> map(fn: (r) => ({r with _value: r._value / 10.0}))
        |> last()
    

    Be aware of the toFloat() and the division by 10.0 instead of 10.