generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Tostring Tonumber

Previous Thread :: Next Thread 
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 09:11 AM
Could someone please explain these?

Thanks.

  ▲
▲ ▲
Try it... Just try it..
Report Abuse
UttermostExedra is not online. UttermostExedra
Joined: 28 Dec 2009
Total Posts: 2483
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
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 09:19 AM
So....

X = (3 + 3 + 3)

tonumber(X) >9

print X

Correct???

  ▲
▲ ▲
Try it... Just try it..
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 09:23 AM
Wait, is this even useful?

  ▲
▲ ▲\n Try it... Just try it..
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
DigitalRunner is not online. DigitalRunner
Joined: 07 Aug 2011
Total Posts: 193
23 Aug 2011 09:29 AM
The tostring() is not that helpful since you can just do:

num = 1337
string = "".. num
Report Abuse
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 09:29 AM
How often do you see this function or use it?

  ▲
▲ ▲
Try it... Just try it..
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
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
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 10:11 AM
Bump

  ▲
▲ ▲
Try it... Just try it..
Report Abuse
Megamatrixdude is not online. Megamatrixdude
Joined: 06 Dec 2009
Total Posts: 10939
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
ToxicityIII is not online. ToxicityIII
Joined: 11 Nov 2010
Total Posts: 3480
23 Aug 2011 10:44 AM
I don't necessarily need to know this do I?

  ▲
▲ ▲
Try it... Just try it..
Report Abuse
Fl0x is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image