docs-v2/content/flux/v0.x/stdlib/universe/float.md

3.7 KiB

title description menu weight flux/v0.x/tags introduced
float() function `float()` converts a value to a float type.
flux_0_x_ref
name parent identifier
float universe universe/float
101
type-conversions
0.7.0

float() converts a value to a float type.

Function type signature
(v: A) => float

{{% caption %}}For more information, see Function type signatures.{{% /caption %}}

Parameters

v

({{< req >}}) Value to convert.

Examples

Convert a string to a float

float(v: "3.14")// Returns 3.14


Convert a scientific notation string to a float

float(v: "1.23e+20")// Returns 1.23e+20 (float)


Convert an integer to a float

float(v: "10")// Returns 10.0


Convert all values in a column to floats

If converting the _value column to float types, use toFloat(). If converting columns other than _value, use map() to iterate over each row and float() to covert a column value to a float type.

data
    |> map(fn: (r) => ({r with exampleCol: float(v: r.exampleCol)}))

{{< expand-wrapper >}} {{% expand "View example input and ouput" %}}

Input data

_time exampleCol *tag
2021-01-01T00:00:00Z -2 t1
2021-01-01T00:00:10Z 10 t1
2021-01-01T00:00:20Z 7 t1
2021-01-01T00:00:30Z 17 t1
2021-01-01T00:00:40Z 15 t1
2021-01-01T00:00:50Z 4 t1
_time exampleCol *tag
2021-01-01T00:00:00Z 19 t2
2021-01-01T00:00:10Z 4 t2
2021-01-01T00:00:20Z -3 t2
2021-01-01T00:00:30Z 19 t2
2021-01-01T00:00:40Z 13 t2
2021-01-01T00:00:50Z 1 t2

Output data

_time exampleCol *tag
2021-01-01T00:00:00Z -2 t1
2021-01-01T00:00:10Z 10 t1
2021-01-01T00:00:20Z 7 t1
2021-01-01T00:00:30Z 17 t1
2021-01-01T00:00:40Z 15 t1
2021-01-01T00:00:50Z 4 t1
_time exampleCol *tag
2021-01-01T00:00:00Z 19 t2
2021-01-01T00:00:10Z 4 t2
2021-01-01T00:00:20Z -3 t2
2021-01-01T00:00:30Z 19 t2
2021-01-01T00:00:40Z 13 t2
2021-01-01T00:00:50Z 1 t2

{{% /expand %}} {{< /expand-wrapper >}}