Library of Functions


Description


Will try to convert the given argument (for example a string) to a number.

Usage and Arguments


tonumber(argument)

  • argument: an argument of any type to be converted to a number.

Returned Values


number: a number equivalent to the content of the converted argument.

Examples


-- store the string '123' in myString
local myString = '123'
 
-- this will cause an error because Lua can't work out if it should
-- convert the string to a number or the number to a string
if (myString > 100) then
end
 
-- So we force the string to be a number and it works.
if (tonumber(myString) > 100) then
    fibaro:debug("This works - it's more than 100!")
end

See Also


tostring
Lua reference manual 5.2: tonumber