Converting string(scientific) to Double

Hi all,

I have a group of scientific strings that i want to convert to a number/double. I already found some script and help for doing this, but the problem im facing is the string.split. The string.split removes the scientific part and makes it something i cant work with. Still i have to split the list otherwise the python script cant read it either. (See picture)

Does anyone know how i can split my list while keeping the scientific string so i can then replace it to a double?

Thanks in advance!

In your string for the seperator did you actually put a space within it?

I have just tried it and i get the following:

I have used a code block so it is easier to see i have added a space

Yes the Blank string is actualy a space. So how u see the string.split thats what i want but instead i get this:

What version of dynamo are you utilising?

Im using Civil3D 2024 and there i open dynamo in. Dont excacly know if there is another version i should use.

ah i see i have dynamo v2.18.1 2023

Here is another example. The moment i say replace the (e) for something differend (in this case abcd) then it works fine. The moment i put it back to (E) it automaticaly replaces it to this weird numbers even though they are still strings…

Are you on the latest version of Civil 3d 2024 which is 2024.4.1 as this will include a later version of dynamo(V2.19).

I have tried a similar version in Civil 3d 2024.4.1 with dynamo 2.19 and mine seems to work fine.

You could try the python code:

OUT=[]

for a in IN[0]:
	OUT.append(a.split(IN[1]))

Yeah i believe there must be something wrong with the list. Its an import so there must be an issue in here. The moment i type it in myself it works like yours.

Thanks eithere way for helping me out :smiley: , ill see if i can import the list another way.

Do try the python code i added, if that works utilise that. Though from a robust point of view it might be wise to add a “To String” node just before to make sure it is all string data.

Hi,

a solution using System.Decimal.Parse()


# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System
from System import Decimal

toList= lambda x : x if hasattr(x, "__iter__") and not isinstance(x, (str, System.String)) else [x]

input_list = toList(IN[0])

OUT = [Decimal.ToDouble(Decimal.Parse(x, System.Globalization.NumberStyles.Float)) for x in input_list]

import sys
import clr
import System
from System import Decimal

toList= lambda x : x if hasattr(x, "__iter__") and not isinstance(x, (str, System.String)) else [x]

array_array_data = [x.split() for x in toList(IN[0])]
out = []
for array in array_array_data:
    lst_double = [Decimal.ToDouble(Decimal.Parse(x, System.Globalization.NumberStyles.Float)) for x in array]
    out.append(lst_double)
    
OUT = out
1 Like

Pure python version with recursive function to maintain list structure

def string_to_float(strings):
	if isinstance(strings, str):
		if ' ' in strings:
			return [float(i) for i in strings.split()]
		return float(strings)
	return [string_to_float(i) for i in strings]

OUT = string_to_float(IN[0])
1 Like