Style numbers

style_number(
  x,
  digits = 0,
  big.mark = NULL,
  decimal.mark = NULL,
  scale = 1,
  ...
)

Arguments

x

Numeric vector

digits

Integer or vector of integers specifying the number of decimals to round x=. When vector is passed, each integer is mapped 1:1 to the numeric values in x

big.mark

Character used between every 3 digits to separate hundreds/thousands/millions/etc. Default is ",", except when decimal.mark = "," when the default is a space.

decimal.mark

The character to be used to indicate the numeric decimal point. Default is "." or getOption("OutDec")

scale

A scaling factor: x will be multiplied by scale before formatting.

...

Other arguments passed on to base::format()

Value

formatted character vector

See also

Other style tools: style_percent(), style_pvalue(), style_ratio(), style_sigfig()

Examples

c(0.111, 12.3) %>% style_number(digits = 1)
#> [1] "0.1"  "12.3"
c(0.111, 12.3) %>% style_number(digits = c(1, 0))
#> [1] "0.1" "12"