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 intmath.round(const float number, const int precision) → const floatmath.round(input float number) → input intmath.round(input float number, input int precision) → input floatmath.round(series float number) → series intmath.round(series float number, series int precision) → series floatmath.round(simple float number) → simple intmath.round(simple float number, simple int precision) → simple float| Parameter | Type | Required | Description |
|---|---|---|---|
number | const float | yes | The number to round. |
precision | const int | yes | How 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.