Skip to content

floor - Round numerical value down to nearest integer

The floor function will round a given numerical value down to the nearest integer. For example, 1.5 becomes 1, 8.1 becomes 8.

Syntax

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

floor(number: number): number
number: number.floor(): 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 floor function to round down, because there are no fractional users.

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

Instead of a value of 35.5, we now have a value of 35, and a clear signal for the number of licenses we may wish to purchase.