Reference round()

round()

Calculates the integer closest to a number.

For example, round(133.8) returns the value 134.

The second parameter, decimals, is optional. It sets the number of decimal places to use when rounding. For example, round(12.34, 1) returns 12.3. decimals is 0 by default.

round() can also be used in shaders with p5.strands. The following example uses round() to quantize colors in a shader.

Examples

Syntax

round(n, [decimals])

Parameters

n
Number: number to round.
decimals
Number: number of decimal places to round to, default is 0.

Returns

Integer: rounded number.

Related References