CSS SASS修剪转换小数

时间:2016-07-20 16:13:36

标签: sass

如何编辑我的em()转换函数,将以下转换的EM值限制为3位数(例如:1.36em)?

input.scss

@function em($target, $context: $font___base-size) {
    @return ($target / $context) * 1em;
}
body {font-size:em(15px);}

output.css

body {
  font-family: sans-serif;
  font-size: 1.36364em; }

2 个答案:

答案 0 :(得分:0)

使用round() ceil()floor(),如下所示:

round( ($target / $context)*100 ) / 100;

100可以是任何数字10 ^ n,其中n是您想要的小数位数。

Sass-lang documentation on round()

答案 1 :(得分:0)

我会选择这样的事情:

import time, threading

from test27 import Read

print "Hello Welcome"
a = 2; b = 5
t = threading.Thread(target = Read, name = 'Example Thread', args = (a,b))
t.start()
time.sleep(5)
t.flag = 0 # This is not updating the flag variable in Read FUNCTION
t.join() # Because of the above command I am unable to wait until the thread finishes. It is blocking.
print "PROGRAM ENDED"

输出:

// Configuration
$font___base-size : 11px;
$number-of-digits : 2;

// Function
@function em($target, $digits : $number-of-digits, $context: $font___base-size) {
    $n : 1;
    @if $digits > 0 {
        @for $i from 1 through $digits {
            $n : $n * 10;
        }
    }
    @return round(($target / $context) * $n) / $n * 1em;
}

// Example use
body {
    font-size:em(15px);
}