Lua - gmatch scientific notation string to number -
i trying convert string of scientific notation numbers actual numbers.
my test string formatted so:
mystring = 1.000000000000000e+00, 2.000000000000000e+02, -1.000000000000000e+05 my current code:
elements = {} s in mystring:gmatch('%d+%.?%d*') table.insert(elements, s); end return unpack(elements); elements returns following incorrectly:
1.000000000000000 %from first number before "e" 00 %after "e" in first number 2.000000000000000 %from second number before "e" anyone know how can go fixing this?
to me, "actual numbers" means number data type. tonumber() quite scientific notation.
local mystring = [[ 1.000000000000000e+00, 2.000000000000000e+02, -1.000000000000000e+05 ]] local function convert(csv) local list = {} value in (csv .. ","):gmatch("(%s+)%w*,") table.insert(list,tonumber(value)) end return unpack(list) end print(convert(mystring))
Comments
Post a Comment