Number Functions

abs($number) //=> number 

Returns the absolute value of $number. If $number is negative, this returns -$number, and if $number is positive, it returns $number as-is.

SCSS Syntax

@debug abs(10px); // 10px
@debug abs(-10px); // 10px

Sass Syntax

@debug abs(10px) // 10px
@debug abs(-10px) // 10px
ceil($number) //=> number 

Rounds $number up to the next highest whole number.

SCSS Syntax

@debug ceil(4); // 4
@debug ceil(4.2); // 5
@debug ceil(4.9); // 5

Sass Syntax

@debug ceil(4)  // 4
@debug ceil(4.2)  // 5
@debug ceil(4.9)  // 5
comparable($number1, $number2) //=> boolean 

Returns whether $number1 and $number2 have compatible units.

If this returns true, $number1 and $number2 can safely be added, subtracted, and compared. Otherwise, doing so will produce errors.

SCSS Syntax

@debug comparable(2px, 1px); // true
@debug comparable(100px, 3em); // false
@debug comparable(10cm, 3mm); // true

Sass Syntax

@debug comparable(2px, 1px)  // true
@debug comparable(100px, 3em)  // false
@debug comparable(10cm, 3mm)  // true
floor($number) //=> number 

Rounds $number down to the next lowest whole number.

SCSS Syntax

@debug floor(4); // 4
@debug floor(4.2); // 4
@debug floor(4.9); // 4

Sass Syntax

@debug floor(4)  // 4
@debug floor(4.2)  // 4
@debug floor(4.9)  // 4
max($number...) //=> number 

Returns the highest of one or more numbers. A list of numbers can be passed using ....

SCSS Syntax

@debug max(1px, 4px); // 4px

$widths: 50px, 30px, 100px;
@debug max($widths...); // 100px

Sass Syntax

@debug max(1px, 4px)  // 4px

$widths: 50px, 30px, 100px 
@debug max($widths...)  // 100px
min($number...) //=> number 

Returns the lowest of one or more numbers. A list of numbers can be passed using ....

SCSS Syntax

@debug min(1px, 4px); // 1px

$widths: 50px, 30px, 100px;
@debug min($widths...); // 30px

Sass Syntax

@debug min(1px, 4px)  // 1px

$widths: 50px, 30px, 100px 
@debug min($widths...)  // 30px
percentage($number) //=> number 

Converts a unitless $number (usually a decimal between 0 and 1) to a percentage.

SCSS Syntax

@debug percentage(0.2); // 20%
@debug percentage(100px / 50px); // 200%

Sass Syntax

@debug percentage(0.2)  // 20%
@debug percentage(100px / 50px)  // 200%
random($limit: null) //=> number 

If $limit is null, returns a random decimal number between 0 and 1.

SCSS Syntax

@debug random(); // 0.2821251858
@debug random(); // 0.6221325814

Sass Syntax

@debug random()  // 0.2821251858
@debug random()  // 0.6221325814

If $limit is a number greater than or equal to 1, returns a random whole number between 1 and $limit.

SCSS Syntax

@debug random(10); // 4
@debug random(10000); // 5373

Sass Syntax

@debug random(10)  // 4
@debug random(10000)  // 5373
round($number) //=> number 

Rounds $number to the nearest whole number.

SCSS Syntax

@debug round(4); // 4
@debug round(4.2); // 4
@debug round(4.9); // 5

Sass Syntax

@debug round(4)  // 4
@debug round(4.2)  // 4
@debug round(4.9)  // 5
unit($number) //=> quoted string 

Returns a string representation of $number's units.

SCSS Syntax

@debug unit(100); // ""
@debug unit(100px); // "px"
@debug unit(5px * 10px); // "px*px"
@debug unit(5px / 1s); // "px/s"

Sass Syntax

@debug unit(100)  // ""
@debug unit(100px)  // "px"
@debug unit(5px * 10px)  // "px*px"
@debug unit(5px / 1s)  // "px/s"
unitless($number) //=> boolean 

Returns whether $number has no units.

SCSS Syntax

@debug unitless(100); // true
@debug unitless(100px); // false

Sass Syntax

@debug unitless(100)  // true
@debug unitless(100px)  // false