Curriculum
Course: Sass Functions
Login
Text lesson

Sass Numeric Functions

Below is a table enumerating all numeric functions available in Sass:

Function

Description

Examples

Result

percentage($number)

This function converts a number without units into a percentage by multiplying it by 100.

percentage(1.5)

150

percentage(1em)

syntax error

round($number)

This function calculates the closest integer to a given number.

round(7.25)

7

round(7.5)

8

ceil($number)

This function rounds a number upwards to the nearest integer.

ceil(7.25)

8

floor($number)

This function rounds a number downwards to the nearest integer.

floor(7.75)

7

abs($number)

This function returns the magnitude of a number.

abs(7)

7

abs(-7)

7

min($numbers)

This function returns the minimum value from a list of numbers.

min(3, 5, -2, 7, 0)

-2

max($numbers)

This function returns the maximum value from a list of numbers.

max(3, 5, -2, 7, 0)

7

random()

This function generates a random value between 0 and 1, exclusive of both bounds.

random()

0.87267

random($limit)

This function returns a random integer within the range from 1 to the value specified by $limit, inclusive.

random(4)

3