Rounds a number down to the whole number at or below it; a whole number stays as it is.
math.floor rounds down: 2.9 gives 2 and -2.1 gives -3. Whole numbers pass through unchanged.
Use it to snap values to a grid, or to turn a fractional length into a valid integer one.
Syntax
math.floor(number: simple int/float) -> simple int
math.floor(number: input int/float) -> input int
math.floor(number: const int/float) -> const int
math.floor(number: series int/float) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | const/ | required | The number to round down. |
Returns
const/input/simple/series int: the whole number at or below the input.
Remarks
- Contrast with truncation:
math.floor(-2.1)is -3, not -2.
Example
//@version=6
indicator("Price grid", overlay = true)
step = input.float(1.0, "Grid", minval = 0.01)
plot(math.floor(close / step) * step, "Grid floor", color = color.blue, style = plot.style_stepline)See also
Runs on Sidechair