Convert Double to Integer

I’m exporting some info to Excel and then later reading it back in.
The problem I’m having right now is with Element IDs.
I thought I was doing List.IndexOf (or List.AllIndicesOf) wrong, but it turns out that when I read the IDs in from Excel, they come in as Doubles, but when I get an Element ID from Revit, it’s an Integer. So they don’t match.
I tried getting around it by setting the readAsStrings option in the Excel.ReadFromFile node, but that’s a global setting, and I have other cells I need to have as numbers.
I’ve also tried Math.Round, but that can’t handle arrays, just single values.

All I really want to do is convert a list of Doubles (123456.000000) to Integers (123456)
(Ive already read these threads:)
http://dynamobim.org/forums/topic/how-to-find-index-for-each-sublist/#post-43035
http://dynamobim.org/forums/topic/indexof-cant-find-multiple-index-really/
http://dynamobim.org/forums/topic/from-decimal-number-to-integer/
They all helped, but nothing worked as a final solution

1 Like

OK, I found the String.ToNumber node, which helps a bit.
But, still: YEEESH I have to jump through a LOT of hoops converting things back and forth just to compare a number with a decimal to an integer, even if they are have same value.
If Math.Round could handle a List, or if IndexOf could compare a Double and an Integer, I could take a dozen nodes out of my graph.

11 Likes

Math.Round can handle lists. Have you tried to change the lacing? It will not give you a integer type though:

2 Likes

Thank you for this Einar! The 2’nd option worked fantastic for me! This was precisely the last key in a script that I’ve been thinking about for two days!! Will save us countless hours of time in the future :smiley:

1 Like

I usually just convert the IDs to text for export and import and reformat them as needed.

Integers will convert nicely to text.

Doubles will not, which is where integer conversion is absolutely necessary to avoid pointless rounding zeros.