Skip to contents

Prettifies a numeric vector by rounding, separating thousands and optionally other procedures. Basically a convenience wrapper around round_to() and base::format().

Usage

prettify_nr(
  x,
  round_to = 0.1,
  round_up = TRUE,
  big_mark = "'",
  decimal_mark = ".",
  justify_right = FALSE,
  ...
)

Arguments

x

A numeric vector to prettify.

round_to

Number to round x to. A numeric scalar.

round_up

Whether to round a remainder of exactly to / 2 up or not. Set to FALSE in order to round off.

big_mark

Character used between every 3 digits to separate thousands.

decimal_mark

Character used to indicate the numeric decimal point. Only relevant if x does not solely consist of integers.

justify_right

Whether to right-justify the results to a common width. See the trim parameter of base::format() for details.

...

Further arguments passed on to base::format().

Value

A character vector of the same length as x.

Examples

c(0.11, 11111.11) |> pal::prettify_nr()
#> [1] "0.1"      "11'111.1"

c(0.11, 11111.11) |>
  pal::prettify_nr(justify_right = TRUE) |>
  pal::cat_lines()
#>      0.1
#> 11'111.1