round()
Rounds a number to the given number of decimal places.
Syntax
round(number, digits)
Description
If the second argument isn't given, it rounds to the nearest integer. If given, it rounds to that many decimal places.
Parameters
| number | The number to round. |
| digits(optional) | How many decimal places to keep (default 0). |
Returns
The rounded number.
Example
Loading editor…
Expected output
3.14 3
When to use?
For making values like money, averages and percentages readable.
Common mistakes
- ⚠️ round(2.5) gives 2 (banker's rounding); it doesn't always round up.