Skip to content

Instantly share code, notes, and snippets.

@napotopia
Created February 17, 2022 20:20
Show Gist options
  • Save napotopia/4e02ce37cffa9d8afdfbd8248d1d4013 to your computer and use it in GitHub Desktop.
Save napotopia/4e02ce37cffa9d8afdfbd8248d1d4013 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
@use "sass:math";
@use "sass:map";
@function round-decimal($number: 0, $decimals: 1) {
$precision: 1;
@if $decimals > 0 {
@for $i from 1 through $decimals {
$precision: $precision * 10;
}
}
$rounded-number: math.round($number * $precision) / $precision;
@return $rounded-number;
}
.foo {
font-size: round-decimal(1.2345);
font-size: round-decimal(1.2345, 0);
font-size: round-decimal(1.2345, 1);
font-size: round-decimal(1.2345, 2);
font-size: round-decimal(1.2345, 3);
}
.foo {
font-size: 1.2;
font-size: 1;
font-size: 1.2;
font-size: 1.23;
font-size: 1.235;
}
{
"sass": {
"compiler": "dart-sass/1.32.12",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment