数字节点
概述
数字节点用于输出一个常量数值或将输入值转换为数字。它还可以配置为将数字四舍五入到指定的小数位数。
- 输入
- 输出
- 编辑器设置
输入项
标题 | 数据类型 | 描述 | 默认值 | 备注 |
---|---|---|---|---|
Input | any | The value to be converted into a number. | (empty) | This input is only available if Use Value Input is enabled. The input will be coerced to a number. |
输出
标题 | 数据类型 | 描述 | 备注 |
---|---|---|---|
Value | number | The output number value. This can either be a constant value or a converted input value. | None |
编辑器设置
设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
---|---|---|---|---|
Value | The constant number value to be outputted. | 0 | Yes | number |
Round | If enabled, the output number will be rounded to the specified decimal places. | false | No | N/A |
Round To | The number of decimal places to round the output number to. | 0 | No | N/A |
示例1:输出一个常量数字
- 创建一个Number节点。
- 将
Value
设置为123.456
。 - 运行图表。Number节点的
Value
输出应为123.456
。
示例2:将字符串转换为数字
- 创建一个文本节点并将文本设置为
123.456
。 - 创建一个Number节点并启用
Use Value Input
设置。 - 将文本节点连接到数字节点的
Input
。 - 运行图表。Number节点的
Value
输出应为123.456
。
示例3:四舍五入一个数字
- 创建一个数值节点。
- 将
Value
设置为123.456
。 - 启用
Round
设置并将Round To
设为2
。 - 运行图表。Number节点的
Value
输出应为123.46
。
错误处理
在正常情况下,Number节点不会报错。如果Input
值无法转换为数字,它将默认使用Value
设置。
常见问题
问:我可以用Number节点将布尔值转换为数字吗?
答:是的,您可以使用数值节点将布尔值转换为数字。true
值将被转换为1
,而false
值将被转换为0
。
问:如果我将非数值连接到Number节点的Input
会发生什么?
A: Number节点会尝试将输入值转换为数字。如果转换不可行,该节点将默认使用Value
设置。
问:我可以用Number节点将数字四舍五入为整数吗?
A: 是的,你可以使用Number节点将数字四舍五入为整数,方法是启用Round
设置并将Round To
设为0
。