Floating point SASS如何将1/3除法的浮点结果四舍五入到33.33334?
在SASS中,通过除以Floating point SASS如何将1/3除法的浮点结果四舍五入到33.33334?,floating-point,sass,Floating Point,Sass,在SASS中,通过除以1/3结果为33.33333,浏览器将此大小的三个元素相加为99.984。我需要的是准确的数字100,这可以通过堆叠三个大小为33.33334的元素来实现。我怎样才能强迫SASS把最后一个师的人数凑齐 演示:好的,解决方案是使用Terkel编写的外部函数 他的十进制四舍五入功能: 用法 您必须使用乘法、除法和ceil()使用自己的舍入方法 为什么我在这个问题上投了反对票? .tile { &-1-3 { width: decimal-ceil(100/3
1/3
结果为33.33333
,浏览器将此大小的三个元素相加为99.984
。我需要的是准确的数字100
,这可以通过堆叠三个大小为33.33334
的元素来实现。我怎样才能强迫SASS把最后一个师的人数凑齐
演示:好的,解决方案是使用Terkel编写的外部函数 他的十进制四舍五入功能: 用法
您必须使用乘法、除法和
ceil()
使用自己的舍入方法
为什么我在这个问题上投了反对票?
.tile {
&-1-3 {
width: decimal-ceil(100/3, 5);
// this should result as 33.33334%;
}
&-2-3 {
width: 2/3 * 100%;
}
&-1-1 {
width: 3/3 * 100%;
}
}
.tile {
&-1-3 {
$num: 1 / 3; // 0.33333
// the number we multiply by should have the same number of
// zeros as there are decimal places you want to keep + the
// number of digits there will be on the left side of the decimal
$num: $num * 10000000; // 3333333.33333
// ceil to round up
$num: ceil($num); // 3333334
// divide by that amount again
$num: $num / 10000000; // 33.33334
width: $num * 100%; // 33333.34%
}
}