cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Convert list of string to list of numbers

shefali
Deputy Chef I
Deputy Chef I

Is there a formula that can be used to convert list of String variables to a list of integers ? 

 

I/P is ["1","100","50", "4"] 
O/P [1,100,50,4]

1 ACCEPTED SOLUTION

Hi @shefali,
If you observe my screenshots:

1๏ธโƒฃ In the 2nd and 3rd images,
I used Variable_name: List and Datatype: String. When applying the pluck("v") formula, it automatically converts to List_of_Numbers, so there's no need to explicitly set the data type as List.

2๏ธโƒฃ I have a small curiosity: Why do we need to create two variables with Integer or Number data types to parse a number list?
Answer: There's no need to use two variables. As I suggested, when we apply the pluck("v") formula, it automatically takes care of converting to List_of_Numbers.

3๏ธโƒฃ However, when using list functions, it still treats the variable as a list. Shouldn't it actually be recognized as a number instead?
Could you please share a screenshot? I didnโ€™t fully understand your point here.

Looking forward to your insights! ๐Ÿ˜Š

Thanks and Regards,
Shivakumar K A

View solution in original post

20 REPLIES 20

Prudvi
Executive Chef I
Executive Chef I

Hi @shefali,
Can you check this schema
[
{
"control_type": "text",
"label": "list_num",
"parse_output": "integer_conversion",
"name": "list_num",
"type": "integer",
"of": "integer",
"optional": true,
"details": {
"real_name": "list_num"
},
"initially_expanded": true,
"hint": "Defaults to nil if not supplied.",
"sticky": true
}
]
Regards,
Prudvi

Hi Prudvi, 

I tried updating my int variable schema exactly like yours. Still, the auto-conversion from List String to List Num is not working. Here is my update schema for reference " - 

[
  {
    "control_type": "text",
    "label": "v_tempInt",
    "parse_output": "integer_conversion",
    "name": "v_tempInt",
    "type": "integer",
    "of": "integer",
    "optional": true,
    "details": {
      "real_name": "v_tempInt"
    },
    "initially_expanded": true,
    "hint": "Defaults to nil if not supplied.",
    "sticky": true
  }
]

 

3.jpg4.jpg

Prudvi
Executive Chef I
Executive Chef I

Hi @shefali,
This is the schema of previous step  variable
[
{
"name": "list_str",
"type": "array",
"of": "string",
"label": "list_str",
"optional": true,
"details": {
"real_name": "num"
},
"initially_expanded": true,
"hint": "Defaults to nil if not supplied.",
"sticky": true
}
]
Regards,
Prudvi

Hi Prudvi, 

I tried updating the source List String schema as yours. Still no luck. Here is a snippet schema code. Please let me know if you guys need any more info from me to debug this issue. 

[
  {
    "label": "v_StringTemp",
    "name": "v_StringTemp",
    "type": "array",
     "of": "string",
    "optional": true,
    "details": {
      "real_name": "v_StringTemp"
    },
"initially_expanded": true,
    "hint": "Defaults to nil if not supplied.",
    "sticky": true
  }
]

Prudvi
Executive Chef I
Executive Chef I

Hi @shefali,
is it possible to share the JSON which you are passing to the variable.
Regards,
Prudvi