Sidechair

math.floor()

Browse the reference

Rounds a number down to the whole number at or below it; a whole number stays as it is.

Try it in the editor

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

Pine Script
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 int

Arguments

NameTypeDefaultDescription
numberconst/input/simple/series int/floatrequiredThe 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

Pine ScriptPrice gridOpen in editor
//@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