原始类型与数值类型
booldefault: false
布尔值,其值可以是 true 或 false。
默认 bool 是 false。 {#sls.type.bool}
angledefault: 0deg
角度测量,对应于 90deg、1.2rad、0 25turn 之类的字面量
duration
Section titled “duration”durationdefault: 0ms
动画时长的类型。使用 ms(毫秒)或 s (秒)之类的后缀来表示精度。
floatdefault: 0
有符号的 32 位浮点数。带 % 后缀的数字会 自动除以 100,因此例如 30% 与
0.30 相同。
float 和 int 值具有以下成员函数:
to-fixed(digits: int) -> string
Section titled “to-fixed(digits: int) -> string”返回数字的字符串表示形式,小数点后保留 digits 位。
它的行为类似于 JavaScript 的 toFixed()。
to-precision(digits: int) -> string
Section titled “to-precision(digits: int) -> string”返回数字的字符串表示形式,保留 digits 位有效数字。
它的行为类似于 JavaScript 的 toPrecision()。
这两个函数使用当前区域设置的小数分隔符格式化数字。 参见 数字与字符串之间的转换。
export component FloatToString { property<float> pi: 3.14159; property<string> fixed: pi.to-fixed(2); // "3.14" property<string> precision: pi.to-precision(4); // "3.142"}此外,可以对任何数值以后缀风格调用 数学函数,
例如 (-10).abs() 或 x.round()。
to-string-unlocalized() -> string
Section titled “to-string-unlocalized() -> string”返回数字的字符串表示形式,但不进行本地化。这意味着小数分隔符始终是点。
intdefault: 0
有符号整数。
默认 int 为零。 {#sls.type.int}
length
Section titled “length”lengthdefault: 0px
用于 x、y、width 和 height 坐标的类型。对应于
1px、1pt、1in、1mm 或 1cm 之类的字面量。只要绑定在
可以访问设备像素比的上下文中运行,它就可以与 length 相互转换。
length 是一种距离。
默认 length 为零。 {#sls.type.length}
percent
Section titled “percent”percentdefault: 0%
被解释为百分比的有符号 32 位浮点数。 分配给此类型属性的字面数字必须带 %
后缀。
physical-length
Section titled “physical-length”physical-lengthdefault: 0phx
这是物理像素的数量。要将整数转换为长度 单位,只需乘以
1px。或者要将长度转换为 浮点数,可以除以 1phx。
relative-font-size
Section titled “relative-font-size”relative-font-sizedefault: 0rem
相对字体大小因子,与 Window.default-font-size 相乘,并且可以转换为
length。
请参阅特定语言的 API 参考,了解这些类型如何映射到不同编程语言的 API。
© 2026 SixtyFPS GmbH