|
| 23 Aug 2011 09:11 AM |
Could someone please explain these?
Thanks.
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:15 AM |
Tostring > making a number to string
Tonumber > making a string into a number.
let's say...
poop = function() end
if tonumber(poop) >5 then
STUFF.
Correct me if I'm wrong. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:19 AM |
So....
X = (3 + 3 + 3)
tonumber(X) >9
print X
Correct???
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:21 AM |
q = "20984758247"
print(type(q)) q = tonumber(q) print(type(q))
>string >number
~~{I'm a dangerous sociopath with a long history of violence}~~ ~{I don't understand how you keep forgetting that}~ |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:23 AM |
Wait, is this even useful?
▲ ▲ ▲\n Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:27 AM |
Somewhat, yes. The tonumber function actually has a second argument, which is a base. That second argument will convert your number into whatever base you specified.
~~{I'm a dangerous sociopath with a long history of violence}~~ ~{I don't understand how you keep forgetting that}~ |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:29 AM |
The tostring() is not that helpful since you can just do:
num = 1337 string = "".. num |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:29 AM |
How often do you see this function or use it?
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:32 AM |
I use it when I HAVE to use numbers in a function.
function add(n1,n2) if not tonumber(n1) or not tonumber(n2) then return "Please supply a number" end return n1+n2 end
print(add("HAI",5)) Please supply a number
~~{I'm a dangerous sociopath with a long history of violence}~~ ~{I don't understand how you keep forgetting that}~ |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 09:41 AM |
Could you explain this to me like I'm a reta.rd...
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 10:11 AM |
Bump
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 10:16 AM |
What's to explain?
str="13379001"
print(tonumber(str), type(str), type(tonumber(str)))
num=9001
print(tostring(num), type(num), type(tostring(num)))
[Now son, don't touch that cactus] |
|
|
| Report Abuse |
|
|
|
| 23 Aug 2011 10:44 AM |
I don't necessarily need to know this do I?
▲ ▲ ▲ Try it... Just try it.. |
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
|
| 23 Aug 2011 10:47 AM |
tonumber does also convert numbers to other bases, like my Hexadecimal to Color3 converter.
_G["hextocolor3"]=function(hex) if type(hex)~="string" then return "Invalid hex" end return Color3.new(tonumber(string.sub(1,2),16)/255,tonumber(string.sub(3,4),16)/255,tonumber(string.sub(5,6),16)/255) end
print(_G["hextocolor3"]("FFFFFF"))
--> 1, 1, 1 |
|
|
| Report Abuse |
|
|