Converts a number to an int by dropping the fraction, and keeps na as na.
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
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 intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | const/ | required | The 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
//@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