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

Comments and Discussions!





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.