math.round
Round a series to the nearest whole number.
math.round(x, digits)Nearest value at digits decimal places, halves away from zero. digits defaults to 0, the nearest integer. The rounding reads the stored binary value, so a decimal half that has no exact binary form, such as 1.005 at 2 places, can round down.
Parameters
A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
x | Series | number | - | - | The value to transform. |
digits | Constant | number | 0 | 0 to 10 | Decimal places to round to (an option, written digits=2). 0 rounds to a whole number. |
Output
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
- None.
- Missing values
- na in, na out. A result outside the finite range is a calculation error.
Example
math.round(close)plot(math.round(close), "Rounded close")