Sass Numeric Functions
Sass numeric functions are used to process numerical values.
The following table lists Sass numeric functions:
| Function | Description & Example |
|---|---|
| abs(number) | Returns the absolute value of a number. <br> <br> Example: <br>abs(15) <br>Result: 15 <br>abs(-15) <br>Result: 15 |
| ceil(number) | Rounds a number up to the next whole number. <br> <br> Example: <br>ceil(15.20) <br>Result: 16 |
| comparable(num1, num2) | Returns a boolean indicating whether num1 and num2 are comparable. <br> <br> Example: <br>comparable(15px, 10px) <br>Result: true <br>comparable(20mm, 1cm) <br>Result: true <br>comparable(35px, 2em) <br>Result: false |
| floor(number) | Rounds a number down to the previous whole number. <br> <br> Example: <br>floor(15.80) <br>Result: 15 |
| max(number...) | Returns the maximum value. <br> <br> Example: <br>max(5, 7, 9, 0, -3, -7) <br>Result: 9 |
| min(number...) | Returns the minimum value. <br> <br> Example: <br>min(5, 7, 9, 0, -3, -7) <br>Result: -7 |
| percentage(number) | Converts a number to a percentage. <br> <br> Example: <br>percentage(1.2) <br>Result: 120 |
| random() | Returns a random decimal between 0 and 1. <br> <br> Example: <br>random() <br>Result: 0.45673 |
| random(number) | Returns an integer between 1 and the specified number, inclusive. <br> <br> Example: <br>random(6) <br>Result: 4 |
| round(number) | Rounds a number to the nearest whole number. <br> <br> Example: <br>round(15.20) <br>Result: 15 <br>round(15.80) <br>Result: 16 |