Skip to content

float() - Pine Script Function

float() casts a value to the floating-point type. It is useful when you receive generic inputs (strings, ints, na) and need a numeric result for calculations.

float(x) → const float
NameTypeDescription
xconst int/float/bool/stringValue to convert to float.

const float — result of the cast (na if conversion is not possible).

  • na converts to na.
  • true1.0, false0.0.
  • Strings must be numeric (e.g., "12.5"); otherwise, the result is na.
//@version=5
indicator("float() example", overlay=false)
strInput = input.string("12.5", "String input")
boolInput = input.bool(true, "Bool input")
floatFromString = float(strInput)
floatFromBool = float(boolInput)
plot(floatFromString, "Float from string", color=color.blue)
plot(floatFromBool, "Float from bool", color=color.orange)