Sidechair

float()

Browse the reference

Converts a value to a float; float(na) gives a na that is typed as a float.

Try it in the editor

float(x) returns x as a floating-point number. Its main job is to give na a type: var x = float(na) declares a float variable that starts empty, where var x = na would leave the type unknown.

Integer values convert exactly.

Syntax

Pine Script
float(x: const int/float) -> const float
float(x: input int/float) -> input float
float(x: simple int/float) -> simple float
float(x: series int/float) -> series float

Arguments

NameTypeDefaultDescription
xconst/input/simple/series int/floatrequiredThe value to convert. A number or na.

Returns

const/input/simple/series float: The same number as a float.

Remarks

  • float(na) is na.
  • On Sidechair: float() returns its argument as it is; the engine tracks types loosely, so the cast mainly documents intent and fixes the declared type.

Example

Pine ScriptA float that starts emptyOpen in editor
//@version=6
indicator("float(na)")
var lastHigh = float(na)
if high > nz(lastHigh, high)
    lastHigh := high
plot(lastHigh, "Highest high so far", color.red)

See also

Runs on Sidechair