Skip to content

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

Like many functions in DataPrime, ceil supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

ceil(number: number): number
number: number.ceil(): number

Arguments

NameTypeRequiredDescription
numbernumbertrueAn 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:

aggregate avg(total_licenses) as average_license_usage

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.

aggregate ceil(avg(total_licenses)) as licenses_needed
aggregate total_licenses.avg().ceil() as licenses_needed

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.