int() function

The int() function converts a single value to an integer.

int(v: "4")



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


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:

  1. Use map() to iterate over and update all input rows.
  2. 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"})

    |> map(fn: (r) => ({r with foo: int(v:}))

View input and output

Was this page helpful?

Thank you for your feedback!

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.