/// toFixed() function in Sass /// @author Hugo Giraudel /// @param {Number} $float - Number to format /// @param {Number} $digits [2] - Number of digits to leave /// @return {Number} @function to-fixed($float, $digits: 2) { $sass-precision: 5; @if $digits > $sass-precision { @warn "Sass sets default precision to #{$sass-precision} digits, and there is no way to change that for now." + "The returned number will have #{$sass-precision} digits, even if you asked for `#{$digits}`." + "See https://github.com/sass/sass/issues/1122 for further informations."; } $pow: pow(10, $digits); @return round($float * $pow) / $pow; } /// Power function /// @param {Number} $x /// @param {Number} $n /// @return {Number} @function pow($x, $n) { $ret: 1; @if $n >= 0 { @for $i from 1 through $n { $ret: $ret * $x; } } @else { @for $i from $n to 0 { $ret: $ret / $x; } } @return $ret; } // returns square root of a given number @function sqrt($r) { $x0: 1; $x1: $x0; @for $i from 1 through 10 { $x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0); $x0: $x1; } @return $x1; } @function strip-unit($number) { @if type-of($number) == 'number' and not unitless($number) { @return $number / ($number * 0 + 1); } @return $number; }