R/add_commas.R

Defines functions add_commas

Documented in add_commas

# add_commas
#' Add commas to a large number
#'
#' Convert a number to a string, with commas every 3rd digit
#'
#' @param numbers Vector of non-negative numbers (will be rounded to integers)
#'
#' @export
#' @return Character string with numbers written like `"7,547,085"`.
#'
#' @examples
#' add_commas(c(231, 91310, 2123, 9911001020, 999723285))
add_commas <-
    function(numbers)
{
    format(numbers, big.mark=",", scientific=FALSE, trim=TRUE)
}

Try the broman package in your browser

Any scripts or data that you put into this service are public.

broman documentation built on July 8, 2022, 5:07 p.m.