Skip to content

int() - Pine Script Function

int() casts a value to an integer. Floating-point numbers are truncated toward zero, booleans map to 1/0, and strings must represent numeric values.

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

const int — result of the cast (na if conversion fails).

  • int(1.9)1; int(-1.9)-1.
  • true1, false0.
  • Non-numeric strings return na.
//@version=5
indicator("int() example", overlay=false)
floatInput = input.float(12.75, "Float value")
boolInput = input.bool(false, "Bool value")
strInput = input.string("42", "String value")
intFloat = int(floatInput)
intBool = int(boolInput)
intStr = int(strInput)
plot(intFloat, "From float", color=color.blue)
plot(intBool, "From bool", color=color.orange)
plot(intStr, "From string", color=color.green)