math.round

Rounds number to the nearest whole number and returns an int. Pass a precision as well and the function keeps decimal places instead: the result is then a float, not an int. That change of return type is the practical difference between the two forms, so pick the form by what you need back - an int to count with, a float to plot. In the series form the precision is itself series, so how many places you keep can differ from bar to bar.

math.round(const float number) → const int
math.round(const float number, const int precision) → const float
math.round(input float number) → input int
math.round(input float number, input int precision) → input float
math.round(series float number) → series int
math.round(series float number, series int precision) → series float
math.round(simple float number) → simple int
math.round(simple float number, simple int precision) → simple float
ParameterTypeRequiredDescription
numberconst floatyesThe number to round.
precisionconst intyesHow many decimal places to keep. It is an int, and it is required in the two-argument form - there is no default to fall back on.

Returns const float or const int or input float or input int or series float or series int or simple float or simple int — An int in the argument’s form from the one-argument form; a float in the arguments’ form from the precision form.

indicator("Close rounded")
plot(math.round(close))

See also math.abs · math.acos · math.asin

Part of the function index.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade