Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Sass 数字函数


Sass 数字函数

数字函数用于操作数字值。

下表列出了 Sass 中所有数字函数

函数 描述 & 示例
abs(number) 返回number的绝对值。

示例
abs(15)
结果: 15
abs(-15)
结果: 15
ceil(number) number向上舍入到最接近的整数。

示例
ceil(15.20)
结果: 16
comparable(num1, num2) 返回num1num2是否可比较。

示例
comparable(15px, 10px)
结果: true
comparable(20mm, 1cm)
结果: true
comparable(35px, 2em)
结果: false
floor(number) number向下舍入到最接近的整数。

示例
floor(15.80)
结果: 15
max(number...) 返回多个数字中的最高值。

示例
max(5, 7, 9, 0, -3, -7)
结果: 9
min(number...) 返回多个数字中的最低值。

示例
min(5, 7, 9, 0, -3, -7)
结果: -7
percentage(number) number转换为百分比(将数字乘以 100)。

示例
percentage(1.2)
结果: 120
random() 返回 0 到 1 之间的随机数。

示例
random()
结果: 0.45673
random(number) 返回 1 到number之间的随机整数。

示例
random(6)
结果: 4
round(number) number舍入到最接近的整数。

示例
round(15.20)
结果: 15
round(15.80)
结果: 16

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.