---
title: Work with floats
description: A float type represents a IEEE-754 64-bit floating-point number. Learn how to work with float types in Flux.
url: https://docs.influxdata.com/flux/v0/data-types/basic/float/
estimated_tokens: 3910
product: Flux
version: v0
---

# Work with floats

A **float** type represents a [IEEE-754](https://standards.ieee.org/standard/754-2019.html) 64-bit floating-point number.

**Type name:** `float`

-   [Float syntax](#float-syntax)
-   [Convert data types to floats](#convert-data-types-to-floats)
-   [Operate on floats](#operate-on-floats)

## Float syntax

A float literal contains a decimal integer, a decimal point, and a decimal fraction.

```js
0.0
123.4
-123.456
```

-   [Scientific notation](#scientific-notation)
-   [Infinity](#infinity)
-   [Not a Number (NaN)](#not-a-number)

### Scientific notation

Flux does not support scientific notation float literal syntax. However, you can use [`float()`](/flux/v0/stdlib/universe/float/) to convert a **scientific notation string** into a float type.

```js
1.23456e+78
// Error: error @1:8-1:9: undefined identifier e

float(v: "1.23456e+78")
// Returns 1.23456e+78 (float)

```

### Infinity

Flux does not support infinite float literal syntax (`+Inf` and `-Inf`). However, you can use [`float()`](/flux/v0/stdlib/universe/float/) to convert a **infinite string** into a float type.

```js
+Inf
// Error: error @1:2-1:5: undefined identifier Inf

float(v: "+Inf")
// Returns +Inf (float)

```

### Not a Number

Flux does not support Not a Number (NaN) float literal syntax. However, you can use [`float()`](/flux/v0/stdlib/universe/float/) to convert a **NaN string** into a float type.

```js
NaN
// Error: error @1:2-1:5: undefined identifier NaN

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

```

## Convert data types to floats

Use the [`float()` function](/flux/v0/stdlib/universe/float/) to convert the following [basic types](/flux/v0/data-types/basic/) to floats:

-   **string**: must be a numeric string or [scientific notation](#scientific-notation)
-   **bool**: `true` converts to `1.0`, `false` converts to `0.0`
-   **int**
-   **uint**

```js
float(v: "1.23")
// 1.23

float(v: true)
// Returns 1.0

float(v: 123)
// Returns 123.0

```

### Convert columns to floats

Flux lets you iterate over rows in a [stream of tables](/flux/v0/get-started/data-model/#stream-of-tables) and convert columns to floats.

**To convert the `_value` column to floats**, use the [`toFloat()` function](/flux/v0/stdlib/universe/tofloat/).

`toFloat()` only operates on the `_value` column.

```js
data
    |> toFloat()
```

##### Given the following input data:

| _time | _value (int) |
| --- | --- |
| 2021-01-01T00:00:00Z | 10 |
| 2021-01-01T02:00:00Z | 20 |
| 2021-01-01T03:00:00Z | 30 |
| 2021-01-01T04:00:00Z | 40 |

##### The example above returns:

| _time | _value (float) |
| --- | --- |
| 2021-01-01T00:00:00Z | 10.0 |
| 2021-01-01T02:00:00Z | 20.0 |
| 2021-01-01T03:00:00Z | 30.0 |
| 2021-01-01T04:00:00Z | 40.0 |

**To convert any column to floats**:

1. Use [`map()`](/flux/v0/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`float()`](/flux/v0/stdlib/universe/float/) to convert columns values to floats.

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

##### Given the following input data:

| _time | index (int) |
| --- | --- |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |

##### The example above returns:

| _time | index (float) |
| --- | --- |
| 2021-01-01T00:00:00Z | 1.0 |
| 2021-01-01T02:00:00Z | 2.0 |
| 2021-01-01T03:00:00Z | 3.0 |
| 2021-01-01T04:00:00Z | 4.0 |

## Operate on floats

-   [Perform arithmetic operations on floats](#perform-arithmetic-operations-on-floats)
-   [Compare float values](#compare-float-values)
-   [Round float values](#round-float-values)
-   [Flux math package](#flux-math-package)

### Perform arithmetic operations on floats

To perform operations like adding, subtracting, multiplying, or dividing float values, use [Flux arithmetic operators](/flux/v0/spec/operators/#arithmetic-operators). Operands must be the same type.

```js
1.23 + 45.67
// Returns 46.9

1.23 - 45.67
// Returns -44.440000000000005

float(v: "12345e+67") * 100.0
// Returns 1.2345000000000001e+73

144.0 / 12.0
// Returns 12.0

10.0 ^ 2.0
// Returns 100.0

```

#### Inherent rounding errors in floating-point arithmetic

To fit an infinite number of real values into a finite number of bits, computer systems must round floating-point values in arithmetic operations. This results in small rounding errors in some operations.

### Compare float values

Use [Flux comparison operators](/flux/v0/spec/operators/#comparison-operators) to compare float values. Operands must be the same type. The operation returns a float.

```js
12345600.0 == float(v: "1.23456e+07")
// Returns true

1.2 > -2.1
// Returns true

```

### Round float values

1. Import the [`math` package](/flux/v0/stdlib/math/).
2. Use [`math.round()`](/flux/v0/stdlib/math/round/) to round to the nearest whole number.

```js
import "math"

math.round(x: 1.54)
// Returns 2.0

```

### Flux math package

Use the [`math` package](/flux/v0/stdlib/math/) to perform operations on float values.

#### Related

-   [float() function](/flux/v0/stdlib/universe/float/)
-   [toFloat() function](/flux/v0/stdlib/universe/tofloat/)

[basic types](/flux/v0/tags/basic-types/) [numeric types](/flux/v0/tags/numeric-types/) [data types](/flux/v0/tags/data-types/)
