math.floor($number) rounds $numberdown to the next lowest whole number (toward -infinity). Whole numbers stay the same. Units such as px are kept. Load it with @use "sass:math" (Dart Sass 1.23+ for modules; global floor() also exists).
Sass resolves the value when you compile. The CSS file only contains the final whole number—unlike browser CSS rounding functions.
Prefer the module form.
Global floor() still works but is deprecated in modern Dart Sass. New stylesheets should use math.floor after @use "sass:math".
Syntax
Syntax
SCSS
@use "sass:math";
math.floor($number); //=> number (units preserved)
math.floor(4); // 4
math.floor(4.2); // 4
math.floor(4.9); // 4
math.floor(4.9px); // 4px
// Global name (legacy / deprecated in modern Dart Sass)
floor(4.9); // 4
// Module API — prefer math.floor after @use "sass:math"
Pattern: compute a fractional length or count → math.floor so you never overshoot → compare with math.ceil and math.round when the rounding direction differs.
Reference
Units and Signs
Floor always moves toward -infinity:
Input
Result
math.floor(4)
4
math.floor(4.2)
4
math.floor(4.9)
4
math.floor(4.9px)
4px
math.floor(-4.2)
-5
math.floor(-4.2px)
-5px
floor vs ceil vs round.
For 4.2: floor → 4, ceil → 5, round → 4. For -4.2: floor → -5, ceil → -4.
Rounds down to the next whole number (toward -infinity).
Keeps units such as px on the result.
Different from ceil/round — pick floor when overshoot is forbidden.
Prefer math.floor over deprecated global floor().
One line: when a fractional Sass number must never overshoot, call math.floor($number).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Pass a number (units optional)
3. Expect the next whole value toward -infinity
4. Prefer math.floor over global floor()
5. Use ceil/round when the direction differs
Frequently Asked Questions
math.floor($number) rounds a number down to the next lowest whole number. Whole numbers stay the same. For example math.floor(4.9) is 4 and math.floor(4) is 4. Units such as px are preserved.
Add @use "sass:math"; at the top of your SCSS file, then call math.floor($number). Example: math.floor(4.9px) compiles to 4px.
floor always rounds down (toward -infinity). ceil always rounds up (toward +infinity). round goes to the nearest whole number. Pick floor when you must never overshoot—for example max columns that still fit.
Yes. Floor still means toward negative infinity. math.floor(-4.2) is -5, not -4. That is different from truncating toward zero.
Yes. The global floor($number) name still works for older stylesheets, but Dart Sass deprecates global built-ins. New projects should prefer math.floor() from sass:math.
Same idea, different stage. Sass math.floor() runs when you compile SCSS. CSS rounding functions run in the browser. Use Sass when the value must be fixed in the output CSS.