Difference between revisions of "Tonumber"

From ComputerCraft Wiki
Jump to: navigation, search
m
m (Added to CAT:LuaForeFunctions.)
Line 16: Line 16:
 
}}
 
}}
 
}}
 
}}
 +
 +
[[Category:Lua_Core_Functions]]

Revision as of 21:23, 28 November 2012


Grid Redstone.png  Function tonumber
Converts a string into a number
Syntax tonumber(string to be converted into a number (needs to be a number))
Returns nil
Part of ComputerCraft
API none

Examples

Grid paper.png  Example
Converts the strings into numbers and adds the together. (It would be more intelligent to just save it as a number.)
Code
number1 = "10"
number2 = "5"
print (number1, " + ", number2, " = ", tonumber (number1) + tonumber (number2))
Output 10 + 5 = 15