round() : Round to Nearest
On this page
Summary
Round a number to the nearest integer or specified decimal places.
Signature
round(value, decimals?)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
value |
Number | Yes | The number to round |
decimals |
Number | No | Number of decimal places (default: 0) |
Returns
Type: Number
The rounded value.
Examples
Round to Integer
Data:
doc.Params["model"] = new {
value = 19.6
};
Output:
<p>Rounded: 20</p>
Round to 2 Decimal Places
Data:
doc.Params["model"] = new {
price = 19.995m
};
Output:
<p>Price: $20.00</p>
Round Percentage
Data:
doc.Params["model"] = new {
completed = 17,
total = 25
};
Output:
<p>68.0% complete</p>
Multiple Decimal Places
Data:
doc.Params["model"] = new {
measurements = new[] {
new { name = "Width", value = 12.3456 },
new { name = "Height", value = 8.7654 }
}
};
Output:
<li>Width: 12.346 mm</li>
<li>Height: 8.765 mm</li>
Notes
- Uses standard rounding (0.5 rounds up)
- Default is 0 decimal places (rounds to integer)
- Specify decimal places for precision
- For always rounding up, use
ceiling() - For always rounding down, use
floor() - For truncation without rounding, use
truncate()