Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What is tostring and tonumber?

Asked by 3 years ago

I really don't get on anywhere about how to use them when to use them and why you use them i would really apperocate if u know anything about it please try to explain to me.

0
"Conversely, numbers can be converted to strings with the tostring()" https://developer.roblox.com/en-us/articles/String brodywth 97 — 3y
0
tostring(12324), tonumber('34342134') greatneil80 2647 — 3y
0
Typecasting:> Ziffixture 6913 — 3y

2 answers

Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago
Edited 3 years ago

Please provide code with your answers. Simply posting an explanation does not help someone new to programming understand how to implement a concept programatically.

Tostring and tonumber are ways of converting data into string or number values.

For example, if the name of one of your parts is "3", and you want to change that into a number, to be used for various things, then you could use tonumber.

I hope this helps!

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

tostring() and tonumber() is basically what all these users have said. The tostring() function simply converts a number to a string, as shown below:

local numberToString = 15
print(tostring(numberToString)) 

The tonumber() function simply converts a string to a number, as shown below:

local stringToNumber = "15"
print(tonumber(stringToNumber))

You can also check if they have changed data types by using the type() function.

local numberToString = 15
print(type(numberToString)) -- This would output 'number'

local conversion = tostring(numberToString)
print(type(conversion)) -- It would now output 'string'

Hope this helps.

Answer this question