Syntax
printf(format, a…any)
sprintf(format, a…any)
Description
The printf() function formats according to a format specifier and writes to standard output.
The sprintf() function formats according to a format specifier and returns the result.
Example
printf("bool: %t\n", true)
a=sprintf("bool: %t\n", false)
print(a)
printf("int: %d\n", 123)
a=sprintf("int: %d\n", 234)
print(a)
printf("bin: %b\n", 14)
printf("char: %c\n", 33)
printf("hex: %x\n", 456)
printf("float1: %f\n", 78.9)
printf("float2: %e\n", 123400000.0)
printf("float3: %E\n", 123400000.0)
printf("str1: %s\n", "\"string\"")
printf("str2: %q\n", "\"string\"")
printf("str3: %x\n", "hex this")
printf("width1: |%6d|%6d|\n", 12, 345)
printf("width2: |%6.2f|%6.2f|\n", 1.2, 3.45)
printf("width3: |%-6.2f|%-6.2f|\n", 1.2, 3.45)
printf("width4: |%6s|%6s|\n", "foo", "b")
printf("width5: |%-6s|%-6s|\n", "foo", "b")
bool: true
bool: false
int: 123
int: 234
bin: 1110
char: !
hex: 1c8
float1: 78.900000
float2: 1.234000e+08
float3: 1.234000E+08
str1: "string"
str2: "\"string\""
str3: 6865782074686973
width1: | 12| 345|
width2: | 1.20| 3.45|
width3: |1.20 |3.45 |
width4: | foo| b|
width5: |foo |b |