Turning number with decimals as string to number

Hello, I’m trying to position a part based on it’s assigned longtitude and latitude that is stored in a ModuleScript as a table.

This is the format of the data table:

Now, my problem is that I need to turn the output, which is a string to a number, but it has a decimal so I can’t really get tonumber() to work with it as it returns nil.

-- Loop, i equals row of the table, 1 is Tokyo; Starting with 1

local lat = sheet[i][3] --> 1st City; 3rd Column -> Saved as 39.6294
	
print(lat) --> "39.6294"
print(tonumber(lat)) --> nil

Does anyone have any ideas on how to turn the string into a number? Thanks in advance.

Is csv meant to be a string or a table? If not a string then you put the information inside a table with { }

this happens because your file is basically a string within a string.
your string looks like this

""39.6294""

so you’re not doing tonumber("39.6294") you’re doing tonumber(""39.6294"")

to fix it you can cut away the first and last character like this

local str = "\"39.123\""
local newStr = string.sub(str, 2, #str-1)
print(tonumber(newStr))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.