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

ceiling() : Round Up to Integer

Round a number up to the nearest integer.


On this page

Signature

ceiling(value)

Parameters

Parameter Type Required Description
value Number Yes The number to round up

Returns

Type: Integer

The smallest integer greater than or equal to the value.


Examples

Round Up Prices

<p>Rounded Price: ${{ceiling(model.price)}}</p>

Data:

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

Output:

<p>Rounded Price: $20</p>

Calculate Pages Needed

<p>Pages required: {{ceiling(model.items / model.itemsPerPage)}}</p>

Data:

doc.Params["model"] = new {
    items = 47,
    itemsPerPage = 10
};

Output:

<p>Pages required: 5</p>

Minimum Purchase Quantity

<p>Boxes needed: {{ceiling(model.quantity / model.boxSize)}}</p>

Data:

doc.Params["model"] = new {
    quantity = 38,
    boxSize = 12
};

Output:

<p>Boxes needed: 4</p>

Always Round Up

{{#each model.values}}
  <li>{{this}} → {{ceiling(this)}}</li>
{{/each}}

Data:

doc.Params["model"] = new {
    values = new[] { 1.1, 2.5, 3.9, 4.0 }
};

Output:

<li>1.1 → 2</li>
<li>2.5 → 3</li>
<li>3.9 → 4</li>
<li>4.0 → 4</li>

Notes

  • Always rounds up (towards positive infinity)
  • Returns integer type
  • For down rounding, use floor()
  • For nearest rounding, use round()
  • For removing decimals without rounding, use truncate()
  • Negative numbers round towards zero: -1.5 → -1

See Also