Rounding numbers in Sass and adjusting the amount of decimals

后端 未结 5 1961
失恋的感觉
失恋的感觉 2020-12-10 15:06

Is their a way in sass to change the digit that rounding occurs on, I would like to stop rounding of a number like this 2.0242914979757085% to this 2.024%. I would like to a

5条回答
  •  不知归路
    2020-12-10 15:37

    You could also do the following:

    @function ceilHundredths($numbers) {
        $numbers: $numbers * 10000;
    
        @if ($numbers < 1) {
            $numbers: $numbers - 1;
    
        } @else {
            $numbers: $numbers + 1;
        }
    
        @return round($numbers)/ 100#{"%"};
    
    }
    
    .test--regular {
        margin-left: percentage( -1 / 3 );
    }
    
    .test {
        margin-left: ceilHundredths( -1 / 3 );
    }
    
    .test--regular--2 {
        margin-left: percentage( 1 / 3 );
    }
    
    .test--2 {
        margin-left: ceilHundredths( 1 / 3 );
    }
    

提交回复
热议问题