代码开发/Built_in_methods_and_variables/Data_transformation_functions
数字(Numbers)#
本文档列出了 n8n 表达式中用于数字数据转换的内置便捷函数。 表达式中的 JavaScript 你可以在表达式中使用任意 JavaScript 代码。更多信息请参考 表达式。
ceil(): Number #
将一个数字向上舍入到最接近的整数。
floor(): Number #
将一个数字向下舍入到最接近的整数。
format(locales?: LanguageCode, options?: FormatOptions): String #
该方法是对 Intl.NumberFormat() 的封装。根据提供的 LanguageCode 和 FormatOptions 返回格式化后的数字字符串。若未提供参数,则以类似 1.234 的格式输出数字。
函数参数#
locales
可选,字符串类型
IETF BCP 47 语言标签。
默认值:en-US
options 可选,对象类型 用于配置数字格式化的选项。详见 MDN | Intl.NumberFormat()。
isEven(): Boolean #
如果数字为偶数则返回 true。仅适用于整数。
isOdd(): Boolean #
如果数字为奇数则返回 true。仅适用于整数。
round(decimalPlaces?: Number): Number #
将数字四舍五入到最接近的整数;若指定了小数位数,则保留相应的小数位。
函数参数#
decimalPlaces
可选,数值类型
指定要保留的小数位数。
默认值:0
toBoolean(): Boolean #
将数字转换为布尔值。0 转换为 false,其余所有值均转换为 true。
toDateTime(format?: String): Date #
将数字转换为 Luxon 日期对象。
函数参数#
format
可选,字符串类型,枚举值
可取值为 ms(毫秒)、s(秒)或 excel(Excel 1900 格式)。默认为毫秒(ms)。