Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)

round() : Round to Nearest

Round a number to the nearest integer or specified decimal places.


On this page

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

<p>Rounded: {{round(model.value)}}</p>

Data:

doc.Params["model"] = new {
    value = 19.6
};

Output:

<p>Rounded: 20</p>

Round to 2 Decimal Places

<p>Price: ${{round(model.price, 2)}}</p>

Data:

doc.Params["model"] = new {
    price = 19.995m
};

Output:

<p>Price: $20.00</p>

Round Percentage

<p>{{round((model.completed / model.total) * 100, 1)}}% complete</p>

Data:

doc.Params["model"] = new {
    completed = 17,
    total = 25
};

Output:

<p>68.0% complete</p>

Multiple Decimal Places

{{#each model.measurements}}
  <li>{{this.name}}: {{round(this.value, 3)}} mm</li>
{{/each}}

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()

See Also