Converts a value to a float; float(na) gives a na that is typed as a float.
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
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 floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | const/ | required | The 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
//@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