Difference between revisions of "Tonumber"

From ComputerCraft Wiki
Jump to: navigation, search
m
Line 1: Line 1:
 +
{{lowercase}}
 
{{Function
 
{{Function
 
|name=tonumber
 
|name=tonumber

Revision as of 13:13, 8 July 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