You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS Step Functions中将字符串转换为数字?

在AWS Step Functions中将字符串转换为数字的解决方法
  • 使用ASL内置的States.StringToNumber()函数,这是官方提供的类型转换方法,可直接将合法的数值字符串(整数、浮点数)转为数字类型。
    示例(假设查询参数存放在$.queryStringParameters.num路径下):

    {
      "Type": "Pass",
      "Parameters": {
        "convertedNumber.$": "States.StringToNumber($.queryStringParameters.num)"
      },
      "Next": "后续状态名称"
    }
    
  • 提前校验输入合法性:如果不确定传入的字符串是否为有效数值,可先用States.IsNumeric()做校验,避免转换失败抛出错误:

    {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.queryStringParameters.num",
          "IsNumeric": true,
          "Next": "执行转换的状态"
        }
      ],
      "Default": "处理非法输入的状态"
    }
    

内容的提问来源于stack exchange,提问作者florian norbert bepunkt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 00:20:16