Commit 541ccdc6 authored by Pierre Ynard's avatar Pierre Ynard

lua: fix sign errors in us_tonumber()

parent c4808dbd
...@@ -49,14 +49,23 @@ end ...@@ -49,14 +49,23 @@ end
-- tonumber() for decimals number, using a dot as decimal separator -- tonumber() for decimals number, using a dot as decimal separator
-- regardless of the system locale -- regardless of the system locale
function us_tonumber(str) function us_tonumber(str)
local i, d = string.match(str, "([+-]?%d*)%.?(%d*)") local s, i, d = string.match(str, "^([+-]?)(%d*)%.?(%d*)$")
if i == nil or i == "" then if not s or not i or not d then
return nil
end
if s == "-" then
s = -1
else
s = 1
end
if i == "" then
i = "0" i = "0"
end end
if d == nil or d == "" then if d == nil or d == "" then
d = "0" d = "0"
end end
return tonumber(i) + tonumber(d)/(10^string.len(d)) return s * (tonumber(i) + tonumber(d)/(10^string.len(d)))
end end
-- strip leading and trailing spaces -- strip leading and trailing spaces
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment