ceil - Round numerical value up to nearest integer
The ceil
function will round a given numerical value up to the nearest integer. For example, 1.5
becomes 2
, 8.1
becomes 9
.
Syntax
Arguments
Name | Type | Required | Description |
---|---|---|---|
number | number | true | An expression that returns a number |
Example - Calculating necessary number of licenses
When using SaaS software, it's important to right-size and pick the correct number of licenses for your users. Consider the following documents:
{
total_licenses: 100,
licenses_in_use: 31,
timestamp: 2024-10-10T21:00:00Z
},
{
total_licenses: 100,
licenses_in_use: 35,
timestamp: 2024-10-11T21:00:00Z
},
{
total_licenses: 100,
licenses_in_use: 22,
timestamp: 2024-10-12T21:00:00Z
},
{
total_licenses: 100,
licenses_in_use: 54,
timestamp: 2024-10-13T21:00:00Z
},
One method we may wish to use to avoid over-provisioning is taking an average of the number of licenses in use over a given period. We can do this using the avg
aggregation:
However, this value comes with a decimal place, which isn't an option for us. We can't buy a fraction of a license, so we can use the ceil
function to round up.
Instead of a value of 35.5
, we now have a value of 36
, and a clear signal for the number of licenses we may wish to purchase.
Theme
Light