Skip to content

Issue with Live Sass Compiler and Unexpected Function Results #317

Closed Answered by glenn2223
RawanBee asked this question in Q&A
Discussion options

You must be logged in to vote

So round() is a new CSS function SASS started supporting in v1.65.

By the new standard, you are telling the compiler to round to the nearest 3 (so, 1.15 becomes 0 and 7.813 becomes 9)

You can either declare your own round function (with a different name) that multiplies by 10^x, then divide by it, to get your value; like:

@use 'sass:math';

@function roundP($input, $precision) {  
    $v: math.pow(10, $precision);
    @return math.round($input * $v) / $v;
}

Or you can tell the function to round to the nearest 0.001; like:

@function vw1920($px) {  
    $m: calc($px / 1920);  
    @debug"vw1920 function: px = #{$px}, m = #{$m * 100}";  
    @return Round($m * 100, 0.001) + 0vw;  
}

This is…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RawanBee
Comment options

@glenn2223
Comment options

Answer selected by RawanBee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants