Skip to content
Algo Trade Analytics Docs
Pine library page — review pending. This page is preserved for compatibility but is not part of the reviewed search index. Check the official Pine Script v6 reference before relying on its explanation, signature, or example.

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=6
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)