Home »
Code Examples »
Lua Code Examples
Lua - String formatting using format specifiers Code Example
The code for String formatting using format specifiers
str1 = "Alvin"
str2 = "Alexander"
x = 10
y = 20
-- Basic string formatting
print(string.format("Basic: %s %s",str1,str2))
-- Date formatting
date = 10; month = 5; year = 2022
print(string.format("Formatted date: %02d/%02d/%03d", date, month, year))
-- Decimal formatting
print(string.format("%.4f",108/7))
--[[
Output:
Basic: Alvin Alexander
Formatted date: 10/05/2022
15.4286
--]]
Code by IncludeHelp,
on August 25, 2022 23:06