math.round($number) rounds $number to the nearest whole number. Whole numbers stay the same. Units such as px are kept. Load it with @use "sass:math" (Dart Sass 1.23+ for modules; global round() 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 round() still works but is deprecated in modern Dart Sass. New stylesheets should use math.round after @use "sass:math".
Syntax
Syntax
SCSS
@use "sass:math";
math.round($number); //=> number (units preserved)
math.round(4); // 4
math.round(4.2); // 4
math.round(4.9); // 5
math.round(4.5px); // 5px
// Global name (legacy / deprecated in modern Dart Sass)
round(4.9); // 5
// Module API — prefer math.round after @use "sass:math"
Pattern: compute a fractional length or count → math.round for the nearest whole value → use math.floor or math.ceil when the rounding direction must be forced.
Different from floor/ceil — pick round when closest is fine.
Prefer math.round over deprecated global round().
One line: when a fractional Sass number should snap to the closest whole value, call math.round($number).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Pass a number (units optional)
3. Expect the nearest whole value
4. Prefer math.round over global round()
5. Use floor/ceil when the direction must be forced
Frequently Asked Questions
math.round($number) rounds a number to the nearest whole number. Whole numbers stay the same. For example math.round(4.2) is 4 and math.round(4.9) is 5. Units such as px are preserved.
Add @use "sass:math"; at the top of your SCSS file, then call math.round($number). Example: math.round(4.5px) compiles to 5px.
round goes to the nearest whole number. floor always rounds down (toward -infinity). ceil always rounds up (toward +infinity). Pick round when either direction is fine as long as you land on the closest integer.
Yes. It still picks the nearest whole number. math.round(-4.2) is -4; math.round(-4.6) is -5.
Yes. The global round($number) name still works for older stylesheets, but Dart Sass deprecates global built-ins. New projects should prefer math.round() from sass:math.
Same idea, different stage. Sass math.round() runs when you compile SCSS. CSS rounding functions run in the browser. Use Sass when the value must be fixed in the output CSS.