Converting to a string

Basic types / Numbers / Integer

local number = 42

local s1 = tostring(number)
-- s1 = 42

-- Concatenation converts a number by itself
local s2 = "No. " .. number
-- s2 = No. 42

-- Zero-padded to 3 digits
local s3 = string.format("%03d", number)
-- s3 = 042

print("s1 = " .. s1)
print("s2 = " .. s2)
print("s3 = " .. s3)

-- + does not join: it needs numeric text
local ok, err = pcall(function()
  return "No. " + number
end)
-- ok = false
-- err = main.lua:20: attempt to add a 'string'
-- with a 'number'
print("ok = " .. tostring(ok))
print("err = " .. err)