What does the expression "ToString" mean?

ToString returns a text or string version of a number. To keep it very simple, a number is stored as its value in memory. A text version of that number has the ASCII value of it stored in memory.

So the value 1 as a number is stored as 1. But “1” as a character is stored as its ASCII value, 49.

So in the examples you’ve shown, the + operator has different functions depending on the data type being added; for numbers it adds the values. For strings, it appends the values.

If you didn’t have the ToString() in there, then the “+” function would be ambiguous. Are you adding up a string and the number or appending a string and the number? By converting the number to a string, that ambiguity is removed. Also, you can’t set a number to a text. It needs to be converted.

No, because the function RandomInRange returns a number, and you cannot append a number to a string without a conversion.


RandomInRange returns an integer - a number without a decimal place (e.g. -2, -1, 0, 1, 2 etc).
RandomFloatInRange returns a float, which is a number with the decimal place (e.g. 3.14159).

2 Likes