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

Number to Text

Asked by 10 years ago

I am making a system that can have a number string that I can do math (+1) with and I want it to be changed into a text string so I can put it on a GUI. Is there a certain method or can I do math with a Text String?

2 answers

Log in to vote
4
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

You don't have to convert the number into a string to put in in a GUI, assuming that's all you're putting into that specific text field.

You can't, however, do math operations on a string. You have to convert the string into a number, first, using tonumber().

Ad
Log in to vote
1
Answered by 10 years ago

Tostring is the solution to your question. Here is the wiki page explaining this. http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#tostring I will quickly write out an example

function add(a,b)
    return tostring("The answer to "..a.." + "..b.." is "..a + b)
end

print(add(5,5))

-- output: 10

Oops, I misread the question - I got it the wrong way round. ToNumber is the solution you need.

0
You don't even need tostring for this :P TheMyrco 375 — 10y

Answer this question