int() function
The int()
function converts a single value to an integer.
int(v: "4")
Parameters
v
Value to convert.
int()
behavior depends on the input data type:
Input type | Returned value |
---|---|
string | Integer equivalent of the numeric string |
bool | 1 (true) or 0 (false) |
duration | Number of nanoseconds in the specified duration |
time | Equivalent nanosecond epoch timestamp |
float | Value truncated at the decimal |
uint | Integer equivalent of the unsigned integer |
Examples
- Convert a string to an integer value
- Convert a boolean to an integer value
- Convert a duration to an integer value
- Convert a time to an integer value
- Convert a float to an integer value
- Convert all values in a column to integer values
Convert a string to an integer value
int(v: "3")
// Returns 3 (int)
Convert a boolean to an integer value
int(v: true)
// Returns 1
Convert a duration to an integer value
int(v: 1m)
// Returns 160000000000
Convert a time to an integer value
int(v: 2021-01-01T00:00:00Z)
// Returns 1609459200000000000
Convert a float to an integer value
int(v: 10.12)
// Returns 10
Convert all values in a column to integer values
If updating values in the _value
column, use toInt()
.
To update values in columns other than _value
:
- Use
map()
to iterate over and update all input rows. - Use
int()
to update the value of a column.
The following example uses data provided by the sampledata
package.
import "sampledata"
data = sampledata.float()
|> rename(columns: {_value: "foo"})
data
|> map(fn: (r) => ({r with foo: int(v: r.foo)}))
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, the following resources are available:
InfluxDB Cloud customers can contact InfluxData Support.