Lipi Reference
Lipi

Functions

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.

Syntax · 1 of 8

                math.round(const float number) → const int
              

Arguments

number required const float The value to be rounded.

Return Type

const int

Syntax · 2 of 8

                math.round(input float number) → input int
              

Arguments

number required input float The value to be rounded.

Return Type

input int

Syntax · 3 of 8

                math.round(simple float number) → simple int
              

Arguments

number required simple float The value to be rounded.

Return Type

simple int

Syntax · 4 of 8

                math.round(series float number) → series int
              

Arguments

number required series float The value to be rounded.

Return Type

series int

Syntax · 5 of 8

                math.round(const float number, const int precision) → const float
              

Arguments

number required const float The value to be rounded.
precision required const int Optional argument. Decimal places to which number will be rounded. When no argument is supplied, rounding is to the nearest integer.

Return Type

const float

Syntax · 6 of 8

                math.round(input float number, input int precision) → input float
              

Arguments

number required input float The value to be rounded.
precision required input int Optional argument. Decimal places to which number will be rounded. When no argument is supplied, rounding is to the nearest integer.

Return Type

input float

Syntax · 7 of 8

                math.round(simple float number, simple int precision) → simple float
              

Arguments

number required simple float The value to be rounded.
precision required simple int Optional argument. Decimal places to which number will be rounded. When no argument is supplied, rounding is to the nearest integer.

Return Type

simple float

Syntax · 8 of 8

                math.round(series float number, series int precision) → series float
              

Arguments

number required series float The value to be rounded.
precision required series int Optional argument. Decimal places to which number will be rounded. When no argument is supplied, rounding is to the nearest integer.

Return Type

series float

Example


          //@lipi=2
indicator("math.round Example", overlay=false)
rounded = math.round(close, 2)
plot(rounded, title="Close to 2 Decimals", color=color.blue)