Function floor()
📝 Description
The floor function returns the closest whole number that is less than or equal to the given value. It effectively "rounds down" by removing the decimal part.
Use Case: Perfect for determining the maximum number of full resources you can afford. If you have enough budget for
4.9servers,floorwill tell you that you can actually only provision4.
💻 Syntax
💡 Examples
1. Basic Rounding Down:
2. Negative Numbers (Be Careful!):
In the negative scale, "less than" means moving further away from zero.
3. Budget Calculation (Real-world scenario):
If you have a budget of $100 and each instance costs $30:
locals {
total_budget = 100
instance_cost = 30
max_instances = floor(local.total_budget / local.instance_cost) # 100 / 30 = 3.33 -> Result: 3
}
⚠️ Comparison Table
| Input | floor() (Down) | ceil() (Up) |
|---|---|---|
1.9 |
1 | 2 |
1.1 |
1 | 2 |
5.0 |
5 | 5 |
-2.1 |
-3 | -2 |
🔗 Related Functions
-
[[ceil]] — Round up to the nearest integer.
-
[[abs]] — Get the absolute value.