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

Could someone explain to me what tostring does and what it can be used for?

Asked by 5 years ago

I've seen it alot but I can't find any explanation. Could someone explain what it does and what it is used for?

1 answer

Log in to vote
0
Answered by
xdeno 187
5 years ago

tostring converts a Number Value such as 1,2,3..99 etc. into a String

For example tostring("50") converts the string "50" to the number 50 Example usage is shown here, which is copied from the wiki:

print("50" == 50)           -- false, because a string is not equal to a number.
print(tostring(50) == "50") -- true, because you converted the number 50 to a string
print(tonumber("50") == 50) -- true, because you converted the string "50" to a number
print(50 .. "" == "50")     -- true, because you tacked on an empty string to the end of the number 50, converting 50 to a string.

Source: https://developer.roblox.com/en-us/articles/String

0
Tostring is a function almost universal across programming languages as well such as Java and Javascript, Python, and C# from my experience. It should take an object given to the function and convert it to a string. Whether it returns the name of the object or information of the object is up to the language's interpreter or compiler. M39a9am3R 3210 — 5y
Ad

Answer this question