Skip to content
Justice Tech School

Formatting Output

format, formatC and sprintf control number output.

Example
x <- 1234567.891
print(format(x, big.mark = ","))
print(format(0.5, nsmall = 2))
print(formatC(42, width = 6, flag = "0"))
print(sprintf("%.1f%%", 45.678))

Exercise

Thousands separator.

format(x, big.mark = "")

Quiz Test

What does sprintf("%.1f", x) do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.