Sidechair

int()

Browse the reference

Converts a number to an int by dropping the fraction, and keeps na as na.

Try it in the editor

int(x) truncates toward zero: int(3.9) is 3 and int(-3.9) is -3. It does not round. Use math.round() for the nearest whole number, math.floor() or math.ceil() to go down or up.

The cast also fixes the declared type of a variable, which matters when an argument asks for an int and you hold a float.

Syntax

Pine Script
int(x: simple int/float) -> simple int
int(x: input int/float) -> input int
int(x: const int/float) -> const int
int(x: series int/float) -> series int

Arguments

NameTypeDefaultDescription
xconst/input/simple/series int/floatrequiredThe value to convert. A number, or na.

Returns

const/input/simple/series int: The number with its fractional part removed.

Remarks

  • int(na) is na.
  • On Sidechair: int() returns its argument as it is; the engine tracks types loosely, so the cast mainly documents intent and fixes the declared type.

Example

Pine ScriptWhole-bar lengthOpen in editor
//@version=6
indicator("int cast")
len = int(10 * 1.5)
plot(ta.sma(close, len), "SMA 15")
plot(int(close), "Close, fraction dropped", color.gray)

See also

Runs on Sidechair