int() - Pine Script Function
Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”int(x) → const intParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
x | const int/float/bool/string | Value to convert. |
Returns
Section titled “Returns”const int — result of the cast (na if conversion fails).
Remarks
Section titled “Remarks”int(1.9)→1;int(-1.9)→-1.true→1,false→0.- Non-numeric strings return
na.
Example
Section titled “Example”//@version=5indicator("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)