Jump to content

What's the different between tonumber and tostring


Hero192

Recommended Posts

Hey guys, i want to be sure of these lua functions ,

tonumber  and  tostring 

don't recomand me the lua.org website because it's hard to get it from them.

Give me some examples only if you are sure you know about these functions i wont get something wrong

Thanks :D

Link to comment

For example:

i have a table i will get something from the table and convert them and tell me if im wrong or right

local Table= {  
{"Jack",900}, 
} 
for index, v in ipairs (Table) do 
outputChatBox(tostring(v[1]).. " got " ..tonumber(v[2]).."$",root,255,0,0) 
end 

Link to comment

You'd use tonumber() if you have a string that you want to convert to a number:

900 == tonumber("900") 
  
-- or 
  
local variable = "1275" 
-- If here you do: 
variable + 50 
-- it will return an error because 'variable' is a string. You'd need to do: 
tonumber(variable) + 50 
  

It's the same otherwise.

  
"900" ~= 900 
  
It'd need to be 
  
"900" == tostring(900) 
  
 

Hope that helps...

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...