Convert to integer in if statement codeblock

I’ve been trying to figure this out. I can convert doubles to integers with “x:int” or “x:int” but can’t find a way to do that in a if statement code block. Anyone know of a way to get this to work?

You can convert any number to an int by rounding (floor or ceiling) as well. That might be easier.

I believe the error is because x:int modifies the existing variable. You might be able to get around this with an imperative statement.

Hope this helps.
You’d need to treat these 3 lists as separate inputs and use it as a condition.

I don’t think I can get the “list1:int;” code block in your example to work because the list I’m trying to convert contains doubles and strings. Only some of the doubles need to be converted. I’m reading from an excel document that has also exported the unit type for parameters which is where I’m getting the “Integer” string from my original example.

An example would be:

parameter storage: [“Double”, “String”, “Integer”, “Integer”, “Double”, “Integer”]
Parameter Value: [47.2, “Beta-LED”, 1, 0, 30.2, 3] <— Note only strings or doubles in this list from excel.
I want to convert indexes 2,3, and 5.

I think I could get indices of “Integer” and then convert those and create a new list of them and then replace item at index using the get indices from the “Integer”, but I was hoping for a more elegant solution.

It should be the same as converting them within the conditional statement, the only difference being you may end up with some null values (only in the conversion list) for non-number types.

Hi @crapai,

There’s no clean solution when it comes to this as it will end up as a bespoke script which you may find really hard to reuse that defeats the purpose of solving an issue through the use of a script. Usually, we need to ensure that the data source is clean, correct and usable. In this case, making sure that your parameter storage value is correct and in relationship to your parameter value.

Another option I would try if I were you is…
I will use the parameter storage as a bool list.
You’ll need to have the list:int as a separate code block as shown above.
The identifier for your IF statement is important. Sort of like a list of true and false.

list1 = what happens if it’s not “Integer”;
list2 = what happens if it’s “Integer”;
false statement = list1;
true statement = list2;
condition = parameter storage == “Integer” ? true statement : false statement;

Hope this helps?