Rounds a number to the nearest whole number, or to a given count of decimal places.
With one argument, math.round returns the nearest whole number. A value exactly halfway goes toward positive infinity: 2.5 gives 3 and -2.5 gives -2.
With a precision argument, math.round keeps that many decimal places and returns a float: math.round(3.14159, 2) is 3.14. The one-argument form returns an int.
Syntax
math.round(number: simple int/float) -> simple int
math.round(number: input int/float) -> input int
math.round(number: const int/float) -> const int
math.round(number: series int/float) -> series int
math.round(number: simple int/float, precision: simple int) -> simple float
math.round(number: input int/float, precision: simple int) -> input float
math.round(number: const int/float, precision: simple int) -> const float
math.round(number: series int/float, precision: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | const/ | required | The number to round to the nearest whole number, or to precision decimals. na gives na. |
| precision | simple/ | required | Number of decimal places to keep. A whole number of 0 or more. |
Returns
simple int: the number rounded to the nearest whole number.input int: the number rounded to the nearest whole number.const int: the number rounded to the nearest whole number.series int: the number rounded to the nearest whole number.simple float: the number rounded to precision decimal places.input float: the number rounded to precision decimal places.const float: the number rounded to precision decimal places.series float: the number rounded to precision decimal places.
Remarks
- Use
math.round_to_mintickto round a price to the instrument's tick size.
Example
//@version=6
indicator("Rounded", overlay = true)
plot(math.round(close, 1), "Close, 1 decimal", color = color.blue, style = plot.style_stepline)
plot(math.round(close), "Close, whole", color = color.red, style = plot.style_stepline)See also
Runs on Sidechair