string.format(formatstring, ...args)
|
Input
|
Description
|
Example
|
|
g
|
Auto†
|
384.63
|
|
G
|
Auto (uppercase)†
|
386
|
|
d or i
|
Signed decimal
|
-392
|
|
u
|
Unsigned decimal
|
1483
|
|
f
|
Decimal float
|
392.65
|
|
o
|
Unsigned octal
|
610
|
|
x
|
Unsigned hex
|
7fa
|
|
X
|
Unsigned hex (uppercase)
|
7FA
|
|
a
|
Hex float
|
-0xc.90fep-2
|
|
A
|
Hex float (uppercase)
|
-0XC.90FEP-2
|
|
e
|
Scientific notation
|
3.9265e+2
|
|
E
|
Scientific notation (uppercase)
|
3.9265E+2
|
|
c
|
Character
|
d
|
|
s
|
String
|
Hello world
|
|
p
|
Pointer
|
b8000000
|
|
%
|
Literal "%"
|
%
|
e or f.
true, false, nil. string.format('%q', 'a string with "quotes" and \n new line') produces:"a string with \"quotes\" and \ new line"
%[flags][width][.precision]specifier
|
'
|
Group number by thousands.
|
|
-
|
Left justify, see width.
|
|
0
|
Pads with 0s instead of spaces, see width.
|
|
+
|
Adds a + sign for positive numbers.
|
|
(space)
|
Inserts a space if there is no sign.
|
|
#
|
For o, x, X:
Add 0, 0x, 0X to non-zero numbers. For a, A, e, E, f, F, g, G: Always write a decimal point. |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.