Description
The round
function rounds the given number number
to the specified number of decimal places, defined by precision
.
Syntax
round(number, precision)
Arguments
Argument | Description |
---|---|
number |
The number to be rounded. |
precision |
The number of decimal places to round to. If precision is 0, the number is rounded to the nearest whole number. |
Return Types
The function returns the rounded number. The return value is of type number (number
).
Examples
Example | Result |
---|---|
round(3.14159, 2) |
3.14 |
round(5.678, 0) |
6 |
round(-1.2345, 3) |
-1.235 |
Notes
- The function considers both positive and negative numbers.
- If
precision
is negative, the number is rounded accordingly before the decimal point. For example,round(1234.56, -2)
results in1200
.
Comments
0 comments
Please sign in to leave a comment.