Sass 和四舍五入数字.这个可以配置吗? [英] Sass and rounding down numbers. Can this be configured?
问题描述
我有什么办法可以修改 Sass 处理小数位的方式吗?看到有几个人说Sass会动态做响应式布局所需的(target/parent)*100计算,并在编译时输出结果.它甚至还有一个百分比函数,它基本上会取两个值并执行此操作.
Is there any way for me to modify the way that Sass will handle decimal places? I saw a few people saying that Sass will dynamically do the (target/parent)*100 calculation needed for responsive layouts, and output the result at compile time. It even has a percentage function, which will essentially take the two values and do this.
唉,Sass 只会给我 3 位小数.到目前为止,我的理解是,在某些情况下,这可能不足以让所有浏览器正确显示布局而不会出现任何问题.
Alas, Sass will only ever give me 3 decimal places. My understanding up to this point has been that in some cases, this may not be a sufficient degree of accuracy for all browsers to properly display the layout without any hiccups.
谁能帮我弄明白这件事的真相?
Can anyone help me get to the bottom of this?
编辑
解决了.如果其他人感兴趣,我设法在 Sass 的 number.rb 中完成了我想要的,改变了 @precision 的值.这改变了所有浮点数的输出方式.
Solved. Incase anyone else is interested, I managed to accomplish what I wanted in Sass's number.rb, changing the value of @precision. This alters the way all floats are output.
推荐答案
如果您使用 Compass,您可以轻松地在项目文件 (config.rb) 中指定精度,而无需破解核心:
If you are using Compass, you can easily specify the precision in your project file (config.rb) without hacking the core:
Sass::Script::Number.precision = 8
有关详细信息,请参阅 Sass 文档
For more information see Sass documentation
这篇关于Sass 和四舍五入数字.这个可以配置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!