Difference between revisions of "Tonumber"

From ComputerCraft Wiki
Jump to: navigation, search
(created the page)
 
Line 2: Line 2:
 
|name=tonumber
 
|name=tonumber
 
|args=[[string (type)|string]] to be converted into a number (needs to be a number)
 
|args=[[string (type)|string]] to be converted into a number (needs to be a number)
|api=none
 
 
|addon=ComputerCraft
 
|addon=ComputerCraft
 
|desc=Converts a string into a number  
 
|desc=Converts a string into a number  
 +
|api=
 
|examples=
 
|examples=
 
{{Example
 
{{Example

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