I think there was something called tonumber()
So, yeah. How do I use tonumber()?
I think there was something called tonumber()
So, yeah. How do I use tonumber()?
Learn to use documentation:
A simple search on the Wiki will result in this page being found:
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#tonumber
tonumber is a function that takes in either one or two arguments.
When given one argument, it returns the decimal number corresponding to the string given, or it may return nil if the thing given isn't a number:
print( tonumber( "1" ) ) -- 1
print( tonumber( "1." ) ) -- 1
print( tonumber( "1.5" ) ) -- 1.5
print( tonumber( "-5.1e3" ) ) -- -5100
print( tonumber( "5kg" ) ) -- nil
print( tonumber( "" ) ) -- nil
print( tonumber( "cat" ) ) -- nil
The second, optional argument, is a base. E.g., we can convert from binary:
print( tonumber( "101", 2 ) ) -- 5
-- since 101 in binary is 5
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
This answer won't be necessary. I figured out how to use it like 20 minutes ago XD
But thanks for helping anyway!