What is tostring() in Lua?

In Lua, you can convert a number to a string using the tostring() function.

%0 node_1 10 node_3 tostring() node_1->node_3 node_1638987714625 "10" node_3->node_1638987714625

Syntax

tostring(number)

Parameters

This function requires a number as a mandatory parameter.

Return value

This function will return the number as a string value.

Code

In this example, we will convert two different numbers and we will see the differences in the output.

mynumber = 10
newstring = tostring(mynumber)
print(mynumber, " is a ", type(newstring))
mynumber2 = 10.0
newstring2 = tostring(mynumber2)
print(mynumber2, " is a ", type(newstring2))

Expected output

10	 is a 	string
10.0	 is a 	string