From string to float without change

Hi there,

I was trying to write a python script to extract a list of values expressed as string, my problem is that when I use the float() function, it changes the values as we can see in the pic

I would like to know how I can change strings to float without any change (including the number of decimals) ?

Thank you in advance

PS: There was no need for rhino file since it’s empty
GIS - World File Parameters - Python (11.0 KB) (249 Bytes)

float() should work. Are you sure it’s not the GH panel that is truncating the decimals/doing scientific notation? Maybe try to print() the values inside the GHPython editor to see what they are?

Also, we would need the .jgw file to inspect further.


Just uploaded the jpw file, and that is the result of printing

Here I observed tht the last two numbers were shorten, which is also undesirable :frowning:

I think this might simply be the inherent floating point arithmetic (and more specifically displaying those), where you could use Decimal() to “see the exact value that’s stored in any particular Python float”:


Are you working on a MAC ?

On a PC, Windows 10, using Rhino SR14 64-bit (5.14.522.8390, 05/22/2017) and GH 0.9.0076.

Sorry to tell you that this way didn’t work, decimal.Decimal can’t be found

But I have found the solution:

import rhinoscriptsyntax as rs
import System.Convert as convert

def worldParam(file):
    paramList =[]
    with open(file, 'r', 0) as worldParamFile:
        for line in worldParamFile:

        return paramList

a = worldParam(worldFile)

The trick was in calling a dotNet System.Convert and the result can be seen in the following pic

thank you for your help.

It should be there, intellisense just doesn’t pick it up. But yes, going through .NET is definitely also an option.

I think there is something funny.

as you can see from the pic, the result of my code is interpreteded as Boolean, if they’re passe through a Panel they are seen as String.

So how can I make sure that “a” will only export a float ???

z = worldParam(worldFile)
a = float(z)

Didn’t work, float expected a string not a list

A quick remark from the side-line: passing anything through a panel will always convert that to a string. So: never-ever do that (unless you really want that result). \o/

1 Like

loop through the values and add(append) them as floats in another list

list = ["1","2","2","3","4"]
for i in range(0, len(list)):

Then a = list2

I tried a similar method as was described up in the thread, and float have resulted in rounding my figures in a way I don’t need.

Thank you for the remark, then here is the other question:

Why the values of a are exported as Boolean from the python component ??

@ivelin.peychev & @wim

Here is the last modification of the file

GIS - World File Parameters - Python (7.5 KB) (249 Bytes)

Google+StackOverflow+ some trial&error experiments

However apparently there’s a .16f limitation coming from Rhino itself. You can’t go further than 16 digits behind the decimal point

Correction, there’s a 16 digits overall limitation.
It is reasonable though, if an object is 1 000 000 000 units of length then .0001 is of no relevance and if an object is 0.0001 units of length the 0.000100000000001 is of no relevance, nor is 100000.00 relevant to the latter.

:smiley: Ironically this is coming from a naval architect who wishes to maintain constant 0.001 mm accuracy for ships.


I don’t know how to express to you that my problem now is that the component exports Boolean and not a number, not an integer and not a float, even when passing through a panel I don´t see a collection of Trues and False, but numbers.

Do you have an explanation for that ?

I believe this is because you function returns the list and not the values of the list, but I’m not that deep in programming to help you further.